#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int T; ll K; // [i桁目まで見た][numより小さいことが確定][前の前の数][前の数] = 場合の数 ll dp[15][2][11][10]; bool checkKado(int a, int b, int c){ if(a == b || b == c || c == a)return false; if(a == 10)return true; return (ac)||(a>b&&b digits[i]){ continue; } if(!checkKado(prepre, pre, cur)){ continue; } dp[i + 1][lessThanNum || cur < digits[i]][pre][cur] += val; } } } } } ll result = 0; rep(lessThanNum, 2)rep(pre, 10)rep(prepre, 10){ result += dp[sz(digits)][lessThanNum][prepre][pre]; } if(sz(digits) > 3){ result += count(stoll(string(sz(digits) - 1, '9'))); } return result; } void solve(){ ll ng = 99, ok = 37294859064823ll, mid; while(ok - ng > 1){ mid = (ok + ng) / 2; ll cnt = count(mid); (cnt >= K ? ok : ng) = mid; } cout << ok << endl; } int main(){ ios::sync_with_stdio(0); cin.tie(0); while(cin >> T){ while(T--){ cin >> K; solve(); } } }