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 canConstruct(a) { var digits = {}; var dig_size = 0; for(var i = 0; i < a.length; i++) { var str = String(a[i]); dig_size += str.length; for(var j = 0; j < str.length; j++) { if(digits[str[j]]) { digits[str[j]]++; } else { digits[str[j]] = 1; } } } var x = 3; var str; while((str = String(x)).length <= dig_size) { var map = JSON.parse(JSON.stringify(digits)); var found = true; for(var i = 0; i < str.length && found; i++) { if(!map[str[i]]) { found = false; } else { map[str[i]]--; if(map[str[i]] < 0) { found = false; } } } if(found) { return "Yes"; } x = x*3; } return "No"; // Return "Yes" or "No" denoting whether you can construct the required number. } function main() { var t = parseInt(readLine()); for(var a0 = 0; a0 < t; a0++){ var n = parseInt(readLine()); a = readLine().split(' '); a = a.map(Number); var result = canConstruct(a); process.stdout.write("" + result + "\n"); } }