#include <bits/stdc++.h>
using namespace std;
int const nax = 53;
using ll = long long;
using ld = long double;
ll const inf = 1e18 + 42;
ll add(ll x, ll y) { return min(inf, x + y); }
ll mul(ll x, ll y) {
  if (y > inf / x) return inf;
  return min(inf, x * y);
}
int pa[60];
ll f[60];
ll dp[60];
int find(int x) { return pa[x] == x ? x : pa[x] = find(pa[x]); }
vector<int> gen_cycle(int n, ll k) {
  vector<int> res(n);
  res[0] = n;
  iota(pa, pa + n, 0);
  set<int> used;
  used.insert(n - 1);
  pa[find(n - 1)] = find(0);
  for (int i = 1; i < n; ++i) {
    for (int t = 0; t < n; ++t) {
      if (!used.count(t) && ((find(i) != find(t)) || i == n - 1)) {
        ll w = (i < n - 1) ? f[n - i - 2] : 1;
        if (w <= k) {
          k -= w;
          continue;
        }
        used.insert(t);
        res[i] = t + 1;
        pa[find(t)] = find(i);
        goto survive;
      }
    }
    throw;
  survive:;
  }
  return res;
}
vector<int> solve(int n, ll k) {
  if (n == 0) return vector<int>();
  for (int i = 1; i <= n; ++i) {
    ll x = mul(i == 1 ? 1 : f[i - 2], dp[n - i]);
    if (x <= k) {
      k -= x;
      continue;
    }
    vector<int> cyc = gen_cycle(i, k / dp[n - i]);
    vector<int> ret = solve(n - i, k % dp[n - i]);
    for (int j : ret) cyc.push_back(i + j);
    return cyc;
  }
  throw;
}
int main() {
  int T;
  int n;
  ll k;
  f[0] = 1;
  for (int i = 1; i <= 55; ++i) f[i] = mul(i, f[i - 1]);
  dp[0] = dp[1] = 1;
  for (int i = 2; i <= 55; ++i) {
    dp[i] = dp[i - 1];
    for (int j = 2; j <= i; ++j) dp[i] = add(dp[i], mul(f[j - 2], dp[i - j]));
  }
  for (scanf("%d", &T); T--;) {
    scanf("%d %lld", &n, &k);
    if (dp[n] < k) {
      printf("-1\n");
      continue;
    }
    --k;
    vector<int> ans = solve(n, k);
    for (int i : ans) {
      printf("%d ", i);
    }
    printf("\n");
  }
}
