def check(v): return v[0] == v[2] and v[1] == v[3] == v[4] and v[0] != v[1] for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) print("Yes" if all(check(A[i * 5 : (i + 1) * 5]) for i in range(N)) else "No")