http://chuyentin.pro/
#include <bits/stdc++.h>
using namespace std;
string solve(string s) {
long long sum=0;
for (int i=0;i < s.length(); i++) sum += (s[i] - '0');
if (sum%9==0) return "Yes";
else return "No";
}
int main(){
string s;
int t;
cin >> t;
while (t--) {
cin >> s;
cout << solve(s) << endl;
}
return 0;
}