import sys
if __name__ == "__main__":
# 读取第一行的n
n = int(sys.stdin.readline().strip())
for i in range(n):
number = int(input())
nums = list(map(int, input().split()))
stack = []
for num in nums:
if stack and stack[-1] != num:
stack.pop()
else:
stack.append(num)
if stack:
print('NO')
else:
print('YES')