#include <fstream>
#include <cstdio>

using namespace std;

int main()
{
    ifstream cin("abcd.in");
    ofstream cout("abcd.out");
    int tests;
    cin >> tests;
    while (tests--)
    {
        int num;
        cin >> num;
        int ab = num / 100, cd = num % 100;
        cout << (((ab * ab + cd * cd) % 7 == 1) ? "YES\n" : "NO\n");
    }
}