#arc173a. A - Neq Number

A - Neq Number

Score: 400400 points

问题陈述

一个正整数 XX 如果满足以下条件,则被称为 "Neq Number"

  • XX 以十进制表示时,没有两个相邻的数字是相同的。

例如,1117317390909090 是 Neq Numbers,而 222263356335 不是。

给定一个正整数 KK。找到第 KK 个最小的 Neq Number。

你需要解决 TT 个测试用例。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

A positive integer XX is called a "Neq Number" if it satisfies the following condition:

  • When XX is written in decimal notation, no two adjacent characters are the same.

For example, 11, 173173, and 90909090 are Neq Numbers, while 2222 and 63356335 are not.

You are given a positive integer KK. Find the KK-th smallest Neq Number.

You have TT test cases to solve.

Constraints

  • 1T1001 \leq T \leq 100
  • 1K10121 \leq K \leq 10^{12}
  • All input values are integers.

Input

The 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:

KK

Output

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

Sample Input 1

3
25
148
998244353

Sample Output 1

27
173
2506230721

For the first test case, here are the smallest 2525 Neq Numbers in ascending order:

  • The nine integers from 11 to 99
  • The nine integers from 1010 to 1919, excluding 1111
  • The seven integers from 2020 to 2727, excluding 2222

Thus, the 2525-th smallest Neq Number is 2727.