https://www.acmicpc.net/problem/5052
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
static StringBuilder sb = new StringBuilder();
static int n;
static String[] phoneNumbers;
static void input() {
Reader scanner = new Reader();
int testNum = scanner.nextInt();
for(int test = 0; test < testNum; test++) {
n = scanner.nextInt();
phoneNumbers = new String[n];
for(int count = 0; count < n; count++) {
phoneNumbers[count] = scanner.nextLine();
}
solution();
}
}
static void solution() {
Arrays.sort(phoneNumbers);
if(isDuplicate()) sb.append("NO").append('\n');
else sb.append("YES").append('\n');
}
static boolean isDuplicate() {
for(int index = 0; index < n - 1; index++) {
if(phoneNumbers[index + 1].startsWith(phoneNumbers[index])) return true;
}
return false;
}
public static void main(String[] args) {
input();
System.out.println(sb);
}
static class Reader {
BufferedReader br;
StringTokenizer st;
public Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch(IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch(IOException e) {
e.printStackTrace();
}
return str;
}
}
}