def is_shitoshitoto(X): return X[0] == X[2] and X[1] == X[3] == X[4] and X[0] != X[1] def solve(): N = int(input()) A = [int(s) for s in input().split()] print("Yes" if all(is_shitoshitoto(A[5 * i : 5 * i + 5]) for i in range(N)) else "No") if __name__ == "__main__": T = int(input()) for _ in range(T): solve()