import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Solution { private static ArrayList insertFirstchar(char first, String rest) { ArrayList restResult = new ArrayList(); for (int i = 0; i <= rest.length(); i++) { String mergeStr = rest.substring(0, i) + first + rest.substring(i); restResult.add(mergeStr); } return restResult; } static ArrayList Permutations(String inputStr) { ArrayList resultArray = new ArrayList(); if (inputStr.length() == 1) { resultArray.add(inputStr); return resultArray; } else { // For separating the first character from the rest of the char char first = inputStr.charAt(0); String rest = inputStr.substring(1); // get all permutations of the rest of the characters ArrayList tempResultArray = Permutations(rest); // using Recursion // for each permutation, for (String permutation : tempResultArray) { ArrayList tempPermut = insertFirstchar(first, permutation); resultArray.addAll(tempPermut); } return resultArray; } } static String canConstruct(int[] a) { // Return "Yes" or "No" denoting whether you can construct the required number. String number = ""; for (int temp : a) { number += temp; } List permutationResults = Permutations(number); for (String temp : permutationResults) { if(Integer.parseInt(temp)%3==0){ return "Yes"; } } return "No"; } 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(); } }