Hill Numbers

No attempts yetTime limit5sMemory limit256 MB

Problem

A hill number is an integer whose digits may rise and then fall, but never fall and then rise again.

  • 12321 is a hill number.
  • 101 is not a hill number.
  • 1111000001111 is not a hill number.

Two neighboring digits may be equal, before the top or after it. Only integers of 0 or more are counted, and 0 is a hill number.

An integer NN is given. If NN is a hill number, print how many hill numbers are smaller than NN. If it is not, print 1-1.

Input

The first line has the number of test cases TT (1T1001 \le T \le 100).

Each of the next TT lines has one integer NN. NN is at least 1 and has at most 70 digits. The answer always fits in a signed 64-bit integer.

Output

Print the answer for each test case on its own line.