import java.io.*;
import java.util.*;
public class Main {
private static void solve() {
int n=sc.nextInt();
Map<String,Set<String>>map=new HashMap<>();
while (n-->0){
String a=sc.next();
String b=sc.next();
String c=sc.next();
if(c.charAt(0)=='a'){
if(map.get(b)!=null){
map.get(b).add(a);
}else {
// Set<String> set = new HashSet<>();
// set.add(a);
// map.put(b,set);
map.put(b,new HashSet<>());
map.get(b).add(a);
}
}
}
int mx=0;
String s="";
for (Map.Entry<String, Set<String>> setEntry : map.entrySet()) {
if(setEntry.getValue().size()>mx){
mx= setEntry.getValue().size();
s=setEntry.getKey();
}
}
out.println(s);
}
public static void main(String[] args) {
int T = sc.nextInt();
while (T-- > 0) {
solve();
}
out.flush();
out.close();
}
static Kattio sc = new Kattio();
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
static class Kattio {
static BufferedReader r;
static StringTokenizer st;
public Kattio() {
r = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
try {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(r.readLine());
}
return st.nextToken();
} catch (Exception e) {
return null;
}
}
public int nextInt() {
char[] str = next().toCharArray();
int i = 0;
boolean neg = false;
if (str[0] == '-') {
i = 1;
neg = true;
}
int ans = 0;
for (; i < str.length; i++) ans = ans * 10 + (str[i] - '0');
return neg ? -ans : ans;
}
public long nextLong() {
char[] str = next().toCharArray();
int i = 0;
boolean neg = false;
if (str[0] == '-') {
i = 1;
neg = true;
}
long ans = 0;
for (; i < str.length; i++) ans = ans * 10 + (str[i] - '0');
return neg ? -ans : ans;
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}