#include <bits/stdc++.h>
const long long INF = 1e18;
int T, n, fa[55];
long long p[55], f[55], k, use[55];
long long mul(long long x, long long y) {
  if (x > INF / y) return INF + 1;
  return x * y;
}
void reduce(long long &x) {
  if (x > INF) x = INF + 1;
}
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
void pt(int n, long long k, int t) {
  printf("%d ", n + t);
  if (n == 2) {
    printf("%d ", t + 1);
    return;
  }
  memset(use, 0, sizeof(use));
  for (int i = 1; i <= n; i++) fa[i] = i;
  use[n] = 1;
  fa[n] = 1;
  for (int i = 2; i < n; i++) {
    int tt = (k - 1) / p[n - i - 1] + 1;
    int j = 1, fx = find(i);
    for (int cnt = 1; cnt <= tt; cnt++, j++)
      while (use[j] || find(j) == fx) j++;
    j--;
    printf("%d ", j + t);
    use[j] = 1;
    fa[fx] = j;
    k = (k - 1) % p[n - i - 1] + 1;
  }
  for (int i = 1; i <= n; i++)
    if (!use[i]) printf("%d ", t + i);
}
void solve(int n, long long k, int t) {
  if (!n) return;
  if (k <= f[n - 1]) {
    printf("%d ", t + 1);
    solve(n - 1, k, t + 1);
    return;
  } else
    k -= f[n - 1];
  for (int i = 2; i <= n; i++) {
    if (mul(p[i - 2], f[n - i]) >= k) {
      pt(i, (k - 1) / f[n - i] + 1, t);
      solve(n - i, (k - 1) % f[n - i] + 1, t + i);
      break;
    }
    k -= mul(p[i - 2], f[n - i]);
  }
}
int main() {
  scanf("%d", &T);
  p[0] = 1;
  for (int i = 1; i <= 50; i++) p[i] = mul(p[i - 1], i);
  f[1] = 1;
  f[0] = 1;
  for (int i = 2; i <= 50; i++) {
    f[i] = f[i - 1];
    for (int j = 2; j <= i; j++) reduce(f[i] += mul(p[j - 2], f[i - j]));
  }
  while (T--) {
    scanf("%d%lld", &n, &k);
    if (f[n] < k) {
      puts("-1");
      continue;
    }
    solve(n, k, 0);
    puts("");
  }
}
