What a Twist

Find the maximum of n times its digitwise nine-complement over all integers from 1 to N for each test case.

Medium5MathGreedyNo attempts yetTime limit1sMemory limit128 MB

Problem

The reversal F(n)F(n) of a positive integer nn is the number you get by replacing every digit aa of nn with 9a9 - a.

Zeros that end up in front of the leading significant digit are ignored. So the reversal of 9 is 0, the reversal of 91 is 8, the reversal of 124 is 875, and the reversal of 990 is 9.

The loveliness of nn is nn multiplied by F(n)F(n).

The loveliness of 124 is 124 times 875, which is 108500

Given a positive integer NN, find the largest loveliness among the numbers from 1 to NN.

Input

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

Each of the next TT lines contains one positive integer NN. (1N10000000001 \le N \le 1000000000)

Output

For each test case, print on its own line the largest loveliness among the numbers from 1 to NN. The answer for the kk-th test case goes on the kk-th line.

Hint

Both 4 and 5 have loveliness 20, and 100 has loveliness 89900.