import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { private static Comparable[] nextPermutation( final Comparable[] c ) { // 1. finds the largest k, that c[k] < c[k+1] int first = getFirst( c ); if ( first == -1 ) return null; // no greater permutation // 2. find last index toSwap, that c[k] < c[toSwap] int toSwap = c.length - 1; while ( c[ first ].compareTo( c[ toSwap ] ) >= 0 ) --toSwap; // 3. swap elements with indexes first and last swap( c, first++, toSwap ); // 4. reverse sequence from k+1 to n (inclusive) toSwap = c.length - 1; while ( first < toSwap ) swap( c, first++, toSwap-- ); return c; } // finds the largest k, that c[k] < c[k+1] // if no such k exists (there is not greater permutation), return -1 private static int getFirst( final Comparable[] c ) { for ( int i = c.length - 2; i >= 0; --i ) if ( c[ i ].compareTo( c[ i + 1 ] ) < 0 ) return i; return -1; } // swaps two elements (with indexes i and j) in array private static void swap( final Comparable[] c, final int i, final int j ) { final Comparable tmp = c[ i ]; c[ i ] = c[ j ]; c[ j ] = tmp; } static String canConstruct(int[] a) { // Return "Yes" or "No" denoting whether you can construct the required number. String number = ""; for (int i = 0; i < a.length; i++) { number += a[i] + ""; } Character[] p = toChar(number.toCharArray()); BigInteger three = new BigInteger("3"); BigInteger b = new BigInteger(number); if (b.mod(three).equals(BigInteger.ZERO)) { return "Yes"; } while (p != null) { p = (Character[]) nextPermutation(p); if (p == null) { break; } b = new BigInteger(new String(toString(p))); // System.out.println(b.toString()); if (b.mod(three).equals(BigInteger.ZERO)) { return "Yes"; } } return "No"; } private static Character[] toChar(char[] a) { Character c[] = new Character[a.length]; for (int i = 0; i < a.length; i++) { c[i] = a[i]; } return c; } private static String toString(Character[] a) { StringBuilder b = new StringBuilder(); for (int i = 0; i < a.length; i++) { b.append(a[i]); } return b.toString(); } 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(); } }