q = gets.to_i q.times do gets a = gets.gsub(' ', '').chars f = false a.permutation.to_a.each do |p| if p.join.to_i % 3 == 0 puts 'Yes' f = true break end end puts 'No' unless f end