This page is still under construction.

Parts of this page are still being built. What you see may change.

ABCD Code

Interview

Time limit2sMemory limit512 MB

Summary
For each four-digit code, check whether the square of its first two digits plus the square of its last two digits leaves remainder 1 modulo 7.
Level

Easy2 of 10

Topics
Math, Implementation, Number theory, Brute force
Solved
No attempts yet

Statement

Vasya often visits Petya. To get into Petya's yard, one must enter a code consisting of four digits. Usually the friends went together, but this time Vasya came alone while Petya waits for him at home.

Vasya does not remember the code, but he has several candidates. He also somehow remembers that the square of the number formed by the first two digits of the code, added to the square of the number formed by the last two digits of the code, leaves a remainder of one when divided by seven. That is, if the code is <<ABCDABCD>>, where <<AA>>, <<BB>>, <<CC>>, <<DD>> are some digits, then AB2+CD2AB^2 + CD^2 leaves a remainder of 1 when divided by 7. For example, the code 2843 is one possible code, since 282+432=2633=376⋅7+128^2 + 43^2=2633 = 376 \cdot 7 + 1, while 8243 is not, since 822+432=8573=1224⋅7+582^2 + 43^2=8573 = 1224 \cdot 7 + 5.

Vasya has several candidates for what the code might be. Help him determine which of the candidates can be the code for the entrance to Petya's yard.

Input

The first line of the input contains the number tt (1≤t≤10 0001 \le t \le 10\,000), the number of code candidates Vasya remembers. Each of the following tt lines contains four digits, one candidate code per line.

Output

Print tt lines. On the ii-th line, print <<YES>> if the ii-th code can be the code for the entrance to Petya's yard, otherwise print <<NO>>.

Examples1

  1. Example 1

    Input
    3
    2843
    8243
    0100
    
    Expected output
    YES
    NO
    YES