T = gets.to_i T.times do n = gets.to_i a = gets.split.map(&:to_i) memo = a.tally memo.default = 0 a.each_cons(2) do |x, y| next if x != y if memo[0] > memo[1] && x == 0 memo[0] -= 1 end if memo[0] < memo[1] && x == 1 memo[1] -= 1 end end if memo[0] == memo[1] puts 'Yes' else puts 'No' end end