import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static boolean per; static String canConstruct(int[] a) { // Return "Yes" or "No" denoting whether you can construct the required number. String str=""; for(int x:a) str+=Integer.toString(x); per=false; rotate(str, 0, str.length()-1); if(per==true) return "Yes"; else return "No"; } private static void rotate(String str, int x, int y) { if (x == y) { if(Integer.parseInt(str)%3==0) { per=true; } } else { for (int i = x; i <= y; i++) { str = swapVar(str,x,i); rotate(str, x+1, y); str = swapVar(str,x,i); } } } public static String swapVar(String str, int x, int y) { char swp; char[] charArray = str.toCharArray(); swp = charArray[x] ; charArray[x] = charArray[y]; charArray[y] = swp; return String.valueOf(charArray); } 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(); } }