import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static String canConstruct(int[] a) { LinkedList digits = new LinkedList(); for (int i : a) { while (i > 0) { digits.add(i % 10); i = i / 10; } } List perms = new LinkedList(); makePermutations(digits,0,perms); for (int i : perms) { if (i % 3 == 0) { return ("Yes"); } } return("No"); // Return "Yes" or "No" denoting whether you can construct the required number. } public static void makePermutations(List l, int number, List s) { if (l.isEmpty()) { s.add(number); } else { for (int i = 0; i < l.size(); i++) { List help = new LinkedList(); for (int j = 0; j < l.size(); j++) { help.add(l.get(i)); } int dig = help.get(i); int n; if (number!=0) { n = number * 10; } else { n=0; } help.remove(i); makePermutations(help,n+dig,s); } } } 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(); } }