t = int(input()) for _ in range(t): n = int(input()) s = input().split() ok = True for i in range(n): base = 5 * i x1 = s[base] x2 = s[base + 1] x3 = s[base + 2] x4 = s[base + 3] x5 = s[base + 4] if not (x1 == x3 and x2 == x4 and x2 == x5 and x1 != x2): ok = False break print('Yes' if ok else 'No')