func_code_string: #include <bits/stdc++.h>   using namespace std;   long long i, j, x, y, curr, T, t, K, N, coun[51], fact[21], rev[51];   vector<int> ans, v;   set<int> cand;   set<int>::iterator it;   void precomp() {     fact[0] = 1;     for (i = 1; i < 21; i++) {       fact[i] = fact[i - 1] * i;     }     coun[0] = coun[1] = 1;     for (i = 2; i < 23; i++) {       coun[i] = fact[i - 2] + coun[i - 1];       for (j = 2; j < i; j++) {         coun[i] += (fact[j - 2] * coun[i - j]);       }     }     for (i = 23; i < 51; i++) coun[i] = coun[22];   }   void fillv(long long n, long long k) {     v.clear();     if (n < 3) {       for (i = n; i > 0; i--) v.push_back(i);       return;     }     cand.clear();     for (i = 1; i < n; i++) {       cand.insert((int)i);       rev[i] = 0;     }     v.push_back(n);     rev[n] = 1;     for (i = 1; i < (n - 1); i++) {       for (j = i + 1; rev[j] > 0; j = rev[j])         ;       x = cand.size();       for (it = cand.begin(), y = 0; y < (k / fact[x - 2]); y++, ++it) {         if (j == (*it)) ++it;       }       if (j == (*it)) ++it;       v.push_back(*it);       rev[*it] = v.size();       cand.erase(it);       k = k % fact[x - 2];     }     v.push_back(*cand.begin());   }   void fill(long long n, long long k) {     int i;     if (n == 0) return;     if (coun[n - 1] > k) {       ans.push_back(ans.size() + 1);       fill(n - 1, k);       return;     }     k -= coun[n - 1];     for (i = 2; i < n; i++) {       j = fact[i - 2] * coun[n - i];       if (j <= k) {         k -= j;         continue;       }       break;     }     fillv(i, k / coun[n - i]);     k = k % (coun[n - i]);     n -= i;     int x = ans.size();     for (j = 0; j < i; j++) {       ans.push_back(x + v[j]);     }     fill(n, k);   }   int main() {     precomp();     cin >> T;     for (t = 0; t < T; t++) {       cin >> N >> K;       if (K > coun[N]) {         cout <<  -1 n ;         continue;       }       ans.clear();       fill(N, K - 1);       for (i = 0; i < N; i++) {         cout << ans[i] <<    ;       }       cout <<   n ;     }     return 0;   }   