Math Contest

Given a huge decimal integer x, print YES if x is divisible by 9 and NO otherwise.

Easy2Number theoryMathStringNo attempts yetTime limit1sMemory limit512 MB

Problem

Problem 2 of the 2016 International Mathematical Olympiad reads as follows.

Find every positive integer nn such that each cell of an n×nn \times n table can be filled with one of the letters I, M and O so that both of the following hold.

  • In each row and each column, one third of the entries are I, one third are M and one third are O.
  • If the number of cells on a diagonal is a multiple of three, then on that diagonal one third of the entries are I, one third are M and one third are O.

The rows and the columns of the table are numbered 1 to nn in order, so each cell corresponds to a pair of integers (i,j)(i, j) with 1i,jn1 \le i, j \le n. For n>1n > 1 the table has 4n24n - 2 diagonals of two types. A diagonal of the first type consists of all cells with the same value of i+ji + j, and a diagonal of the second type consists of all cells with the same value of iji - j.

The answer to that problem is every positive integer divisible by 9, that is, every nn that can be written as n=9kn = 9k for a positive integer kk. You are in a programming contest rather than the olympiad, so the question changes. Given a positive integer xx, decide whether xx can be used as nn in the problem above.

Input

The first line contains the number of test cases TT (1T10001 \le T \le 1000).

Each of the next TT lines contains one integer xx (1x101000001 \le x \le 10^{100000}). Every xx is written in decimal with no leading zeros.

Output

For each test case, print YES if xx can be used as nn, and NO otherwise, one answer per line and without quotes.