/* * Problem link * */ #include using namespace std; struct INIT{INIT(){cin.tie(0);ios_base::sync_with_stdio(false);} }init; typedef long long LL; #define rep(i,n) for(auto i= 0*(n);i b && (b < c) || (ac)))); } int main() { #ifdef INPUT_FROM_FILE ifstream cin("sample.in"); ofstream cout("sample.out"); #endif int T; while (cin >> T) { while (T--) { LL K; cin >> K; vector,LL>> dp(1); rep(i, 10)rep(j,10)if(i!=j) dp[0][mp(i, j)] = 1; LL lb = 1; LL ub = 1; auto cnt = [&]() { rep(i, 9) { range(it, dp.back()) { if (checkKadomatsu(i + 1, it.first.first, it.first.second)) ub+=it.second; } } }; cnt(); while (!(lb <= K&&K, LL> nxt; rep(i, 10) { range(it, dp.back()) { if (checkKadomatsu(i, it.first.first, it.first.second)) nxt[mp(i, it.first.first)] += it.second; } } dp.push_back(nxt); cnt(); } vector res; [&]() { rep(i, 9) { range(it, dp.back()) { if (checkKadomatsu(i + 1, it.first.first, it.first.second)) { if (lb + it.second > K) { res.push_back(i + 1); res.push_back(it.first.first); res.push_back(it.first.second); return; } lb += it.second; } } } }(); dp.pop_back(); while (dp.size() > 0) { range(it, dp.back()) { int p = res[res.size() - 1]; int pp = res[res.size() - 2]; if(p==it.first.first) if (checkKadomatsu(pp, it.first.first, it.first.second)) { if (lb + it.second > K) { res.push_back(it.first.second); break; } lb += it.second; } } dp.pop_back(); } for (auto& i : res)cout << i; cout << endl; } } return 0; }