def solve(board): next = board[0][0] first = True for i in range(len(board)): for j in range(i): if board[i][j] != next: return 'No' if next == 0: next = 1 else: next = 0 if next == 0: next = 1 else: next = 0 else: return 'Yes' t = int(raw_input().strip()) for t_itr in xrange(t): n = int(raw_input().strip()) board = [] for _ in xrange(n): board.append(map(int, raw_input().rstrip().split())) result = solve(board) print result