import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static String canConstruct(int[] a) { // Return "Yes" or "No" denoting whether you can construct the required number. ArrayList perms = recPermute(a[0]); for(int i : perms){ if(i%3 == 0) return "Yes"; } return "No"; } static ArrayList recPermute(int rest){ int size = (int) Math.floor(Math.log10(rest)) + 1; ArrayList toReturn = new ArrayList<>(); if(size <= 1){ toReturn.add(rest); } else{ for(int i = 0;i < size;i++){ int curr = Integer.parseInt((!Integer.toString(rest).substring(i,i+1).equals("")) ? Integer.toString(rest).substring(i,i+1) : "0"); int left = Integer.parseInt((!Integer.toString(rest).substring(0,i).equals("")) ? Integer.toString(rest).substring(0,i) : "0"); int right = Integer.parseInt((!Integer.toString(rest).substring(i+1).equals("")) ? Integer.toString(rest).substring(i+1) : "0"); ArrayList perms = recPermute(right + (left*((int)Math.pow(10,size - i - 1)))); for(Integer j : perms) toReturn.add(curr*((int)Math.pow(10,size-1)) + j); } } return toReturn; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int a0 = 0; a0 < t; a0++){ int n = in.nextInt(); int[] a = new int[n]; for(int a_i = 0; a_i < n; a_i++){ a[a_i] = in.nextInt(); } String result = canConstruct(a); System.out.println(result); } in.close(); } }