## https://yukicoder.me/problems/no/2148 import itertools def solve(N, cd): # RGBごとにまとめる c_map = {} for c, d in cd: if c not in c_map: c_map[c] = [] c_map[c].append(d) c_array = [valeus for valeus in c_map.values()] if len(c_array) == 1: return "YES" ok_count = 0 for p in itertools.combinations(c_array, 2): v1 = p[0] v2 = p[1] v2_set = set(v2) for v in v1: if v in v2_set: ok_count += 1 break if ok_count >= len(c_array) - 1: return "YES" else: return "NO" def main(): T = int(input()) answers = [] for _ in range(T): N = int(input()) cd = [] for _ in range(N): c, d = input().split() cd.append((c, int(d))) ans = solve(N, cd) answers.append(ans) for ans in answers: print(ans) if __name__ == '__main__': main()