#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e6 + 8;
const long long MOD = 1e9 + 7;
const long long sz = 1e5 + 5;
void f_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
}
const long long INF = (long long)1e18 + 60;
long long safe_add(long long x, long long y) { return min(INF, x + y); }
long long safe_mul(long long x, long long y) {
  if (INF / x < y) return INF;
  return min(INF, x * y);
}
const long long N = 52;
long long f[N];
long long dp[N];
vector<long long> kth_cycle(long long s, long long k) {
  vector<long long> res(s, -1);
  res[0] = s - 1;
  for (long long i = 1; i < s; i++) {
    for (long long x = 0; x < s; x++) {
      bool ok = true;
      for (long long j = 0; j < i; j++) ok &= (res[j] != x);
      if (!ok) continue;
      if (i == s - 1) {
        res[i] = x;
        break;
      }
      long long p = x;
      while (p < i) p = res[p];
      if (p == i) continue;
      long long w = f[s - i - 2];
      if (w <= k) {
        k -= w;
        continue;
      }
      res[i] = x;
      break;
    }
  }
  return res;
}
vector<long long> solve(long long n, long long k) {
  vector<long long> res(n);
  if (!n) return res;
  for (long long s = 0; s < n; s++) {
    long long gpwtb = (s == 0 ? 1 : f[(s + 1) - 2]) * dp[n - (s + 1)];
    if (gpwtb <= k) {
      k -= gpwtb;
      continue;
    }
    vector<long long> curr = kth_cycle((s + 1), k / dp[n - (s + 1)]);
    for (long long i = 0; i <= s; i++) res[i] = curr[i];
    curr = solve(n - (s + 1), k % dp[n - (s + 1)]);
    for (long long i = 0; i < n - (s + 1); i++)
      res[i + (s + 1)] = curr[i] + (s + 1);
    return res;
  }
  return res;
}
int32_t main() {
  f_io();
  dp[0] = f[0] = 1;
  for (long long i = 1; i < N; i++) f[i] = safe_mul(i, f[i - 1]);
  for (long long i = 1; i < N; i++) {
    dp[i] = dp[i - 1];
    for (long long j = 2; j < i + 1; j++) {
      dp[i] = safe_add(dp[i], safe_mul(f[j - 2], dp[i - j]));
    }
  }
  long long tc = 1;
  cin >> tc;
  while (tc--) {
    long long n, k;
    cin >> n >> k;
    k--;
    if (dp[n] <= k) {
      cout << "-1"
           << "\n";
      continue;
    }
    auto ret = solve(n, k);
    for (auto el : ret) cout << el + 1 << ' ';
    cout << "\n";
  }
}
