#include <bits/stdc++.h>
using namespace std;
namespace io {
const int l = 1 << 20;
char buf[l], *s, *t, c;
inline void gc() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, l, stdin);
    c = s == t ? EOF : *s++;
  } else
    c = *s++;
}
template <class IT>
inline void gi(IT &x) {
  x = 0;
  gc();
  while (c < '0' || c > '9') gc();
  while ('0' <= c && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    gc();
  }
}
char buf0[20];
int a;
template <class IT>
inline void pi(IT x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  do buf0[++a] = x % 10 + 48;
  while (x /= 10);
  while (a) putchar(buf0[a--]);
  putchar('\n');
}
};  // namespace io
using io::gi;
using io::pi;
template <class IT>
inline void cmax(IT &a, IT b) {
  if (a < b) a = b;
}
template <class IT>
inline void cmin(IT &a, IT b) {
  if (b < a) a = b;
}
const int N = 55;
const long long inf = 1000000000000000001ll;
long long fac[N], c[N], d[N];
int ufs[N], ans[N], vis[N];
inline long long add(long long a) { return a < inf ? a : inf; }
inline long long mul(long long a, long long b) {
  return a ? ((b <= inf / a) ? (a * b) : inf) : 0ll;
}
inline int UFS(int v) { return ufs[v] ? ufs[v] = UFS(ufs[v]) : v; }
int main() {
  int i;
  fac[0] = 1ll;
  for (i = (1); i <= (50); ++i) fac[i] = mul(fac[i - 1], i);
  c[0] = c[1] = c[2] = 1ll;
  for (i = (3); i <= (50); ++i) c[i] = fac[i - 2];
  int T;
  scanf("%d", &T);
  while (T--) {
    memset(vis, 0, sizeof(vis));
    memset(ufs, 0, sizeof(ufs));
    int n, i, j, tp = 0, o, f, q, c0;
    long long k, t;
    scanf("%d%lld", &n, &k);
    d[n + 1] = 1ll;
    for (i = (n); i >= (1); --i) {
      t = 0ll;
      for (j = (i); j <= (n); ++j) t = add(t + mul(d[j + 1], c[j - i + 1]));
      d[i] = t;
    }
    if ((--k) >= d[1]) {
      puts("-1");
      continue;
    }
    for (i = (1); i <= (n); ++i) {
      t = 0ll;
      for (j = (i); j <= (n); ++j) {
        if (k < mul(d[j + 1], c[j - i + 1])) {
          t = k / d[j + 1];
          for (o = (i); o < (j); ++o) vis[o] = 1;
          ans[i] = j;
          for (o = (i + 1); o < (j); ++o) {
            f = UFS(o);
            c0 = t / fac[j - o - 1];
            t -= mul(c0, fac[j - o - 1]);
            for (q = (i); q < (j); ++q)
              if (vis[q] && q != f && !(c0--)) {
                ans[o] = q;
                ufs[q] = f;
                vis[q] = 0;
                break;
              }
          }
          for (o = (i); o < (j); ++o)
            if (vis[o]) {
              ans[j] = o;
              break;
            }
          vis[j] = 1;
          k %= d[(i = j) + 1];
          break;
        } else
          k -= mul(d[j + 1], c[j - i + 1]);
      }
    }
    for (i = (1); i <= (n); ++i) printf("%d ", ans[i]);
    puts("");
  }
  return 0;
}
