#include using namespace std; string swap(string s, int x, int y){ string start = ""; if (x > 0) start = s.substr(0,x); string temp(1, s.at(y)); start.append(temp); if (y > x) start.append(s.substr(x+1,y-x)); string temp2 (1, s.at(x)); start.append(temp2); if (y < s.length()-1) start.append(s.substr(y+1)); return start; } void permutate(string s, int l, int r){ /*if (l == r){ cout << s << "\n"; //if (stoi( s ) % 3 == 0) //return "Yes"; }*/ if (l != r) { for (int i = l; i <= r; i++) { swap(s, l, i); permutate(s, l+1, r); swap(s, l, i); //backtrack } } //return "No"; } string canConstruct(vector a) { // Return "Yes" or "No" denoting whether you can construct the required number. string s; for (int i = 0; i < a.size(); i++){ s.append(to_string(a[i])); } // create several strings if (stoi( s ) % 3 == 0) return "Yes"; /*for (int i = 0; i < s.size(); i++){ string middle = s.substring(i,1); string start = ""; int before_middle = i-0; if (before_middle > 0){ start = } }*/ permutate(s, 0, s.length() - 1); return "No"; } int main() { int t; cin >> t; for(int a0 = 0; a0 < t; a0++){ int n; cin >> n; vector a(n); for(int a_i = 0; a_i < n; a_i++){ cin >> a[a_i]; } string result = canConstruct(a); cout << result << endl; } return 0; }