#include <bits/stdc++.h>
using namespace std;
const long long MX = 2e18;
long long dp[52][52] = {}, fkt[51] = {}, rs[51] = {}, ac[51] = {}, us[51] = {};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fkt[0] = 1;
  for (long long i = 1; i < 20; i++) {
    fkt[i] = fkt[i - 1] * i;
  }
  for (long long i = 20; i <= 50; i++) {
    fkt[i] = MX;
  }
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    dp[n + 1][0] = 1;
    for (int i = 0; i <= n; i++) {
      rs[i] = 0;
      ac[i] = 0;
      us[i] = 0;
      for (int j = 0; j <= n; j++) {
        dp[i][j] = 0;
      }
    }
    for (int i = n; i > 0; i--) {
      for (int j = 1; j <= n - i + 1; j++) {
        if ((double)fkt[max(0, j - 2)] * dp[i + j][n - (i + j) + 1] +
                dp[i][j - 1] >=
            MX) {
          dp[i][j] = 2e18;
        } else {
          dp[i][j] =
              fkt[max(0, j - 2)] * dp[i + j][n - (i + j) + 1] + dp[i][j - 1];
        }
      }
    }
    k--;
    if (dp[1][n] > k) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n - i + 1; j++) {
          if (dp[i][j] > k) {
            k -= dp[i][j - 1];
            rs[i] = i + j - 1;
            us[i + j - 1] = i;
            long long tp = k / dp[i + j][n - (i + j) + 1];
            for (int kk = j - 2; kk > 0; kk--) {
              int to = 0, ig = i + j - 1 - kk;
              while (us[ig]) {
                ig = us[ig];
              }
              for (int l = i; l <= i + j - 1; l++) {
                if (l == ig) {
                  continue;
                }
                to += !us[l];
                if (to > tp / fkt[kk - 1]) {
                  us[l] = i + j - 1 - kk;
                  rs[i + j - 1 - kk] = l;
                  tp %= fkt[kk - 1];
                  break;
                }
              }
            }
            for (int kk = i; kk <= i + j - 1; kk++) {
              if (!us[kk]) {
                rs[i + j - 1] = kk;
                us[kk] = i + j - 1;
                break;
              }
            }
            k %= dp[i + j][n - (i + j) + 1];
            i += j - 1;
            break;
          }
        }
      }
      for (int i = 1; i <= n; i++) {
        cout << rs[i];
        if (i < n) {
          cout << " ";
        }
      }
      cout << "\n";
    } else {
      cout << "-1\n";
    }
  }
  return 0;
}
