#!/usr/bin/python from collections import deque def ir(): return int(raw_input()) def ia(): return map(int, raw_input().split()) def ii(): return raw_input().split() def ss(l): r = [] for e in l: for c in e: r.append(c) return r def nd(l): n = 0 for c in l: n += int(c) n %= 3 return n T = ir() def solve(): n = ir() s = ii() s = ss(s) s = nd(s) print 'Yes' if s == 0 else 'No' for t in xrange(T): solve()