process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function swap (x, y, s){ let temp = s[x]; s[x] = s[y] ; s[y] = temp; } function permutations(n, s){ if(n === 1){ if(Number(s.join('')) % 3 === 0){ return "YES" } } else{ for(let i = 0; i < n - 1; i++){ let result = permutations(n - 1, s); if(result) return result; if( n % 2 === 0){ swap(n-1, i, s); } else{ swap(0, n-1, s); } } let res = permutations(n - 1, s); if(res) return res; } } function canConstruct(a) { // Return "Yes" or "No" denoting whether you can construct the required number. let result = permutations(a.length, a); return result ? "Yes" : "No"; } function main() { var t = parseInt(readLine()); for(var a0 = 0; a0 < t; a0++){ var n = parseInt(readLine()); a = readLine().split(' ').join(''); let s = []; for(let i = 0; i < a.length; i++){ s.push(a[i]); } var result = canConstruct(s); process.stdout.write("" + result + "\n"); } }