#ARC141A. [ARC141A] Periodic Number

[ARC141A] Periodic Number

Score : 400400 points

Problem Statement

For a positive integer nn, let str(n)\mathrm{str}(n) be the string representing nn in decimal.

We say that a positive integer nn is periodic when there exists a positive integer mm such that str(n)\mathrm{str}(n) is the concatenation of two or more copies of str(m)\mathrm{str}(m). For example, 1111, 12121212, and 123123123123123123 are periodic.

You are given a positive integer NN at least 1111. Find the greatest periodic number at most NN. It can be proved that there is at least one periodic number at most NN.

You will get TT test cases to solve.

Constraints

  • 1T1041 \leq T \leq 10^4
  • 11N<101811 \leq N < 10^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

TT

case1\mathrm{case}_1

\vdots

caseT\mathrm{case}_T

Each case is given in the following format:

NN

Output

Print TT lines. The ii-th line should contain the answer for the ii-th test case.

3
1412
23
498650499498649123
1313
22
498650498650498650

For the first test case, the periodic numbers at most 14121412 include 1111, 222222, 12121212, 13131313, and the greatest is 13131313.