#include <bits/stdc++.h>
using namespace std;
const int maxn = 60;
const long long inf = 1e18;
int T, n, ans[maxn], fa[maxn], fr[maxn];
long long k;
long long dp[maxn], p[maxn];
bool ok, f[maxn];
long long calc(int x) {
  if (x <= 1) return 1;
  return p[x - 2];
}
long long mul(long long x, long long y) {
  if (x == 0) return 0;
  if (inf / x + 1 <= y) return inf;
  return x * y;
}
int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
void work(int lc, int now) {
  int rc = lc + now - 1;
  for (int i = lc; i <= rc - 1; i++) fa[i] = i, fr[i] = i;
  ans[lc] = rc;
  f[rc] = 1;
  fa[lc] = rc;
  fr[rc] = lc;
  for (int i = lc + 1; i <= rc - 1; i++) {
    for (int j = lc; j <= rc - 1; j++) {
      if (f[j] || fr[i] == j) continue;
      long long sum = mul(p[rc - i - 1], dp[n - rc]);
      if (sum < k)
        k -= sum;
      else {
        ans[i] = j;
        f[j] = 1;
        fa[i] = gf(j);
        fr[gf(j)] = fr[i];
        break;
      }
    }
  }
  for (int j = lc; j <= rc - 1; j++)
    if (!f[j]) ans[rc] = j;
}
void solve(int lc) {
  if (lc > n) return;
  int left = n - lc + 1;
  bool ff = 0;
  for (int i = 1; i <= left; i++) {
    if (mul(dp[left - i], calc(i)) >= k) {
      ff = 1;
      work(lc, i);
      solve(lc + i);
      break;
    } else
      k -= dp[left - i] * calc(i);
  }
  if (!ff) ok = 0;
}
int main() {
  dp[0] = 1;
  p[0] = 1;
  for (int i = 1; i <= 50; i++) {
    p[i] = mul(p[i - 1], i);
  }
  for (int i = 1; i <= 50; i++)
    for (int j = i - 1; j >= 0; j--)
      dp[i] = min(dp[i] + mul(dp[j], calc(i - j)), inf);
  scanf("%d", &T);
  while (T--) {
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i++) f[i] = 0;
    ok = 1;
    solve(1);
    if (!ok)
      printf("-1\n");
    else {
      for (int i = 1; i <= n; i++)
        printf("%d%c", ans[i], (i == n ? '\n' : ' '));
    }
  }
  return 0;
}
