#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 998244353;
unsigned long long p[55];
unsigned long long f[55];
int d[55], to[55], used[55];
void upd(unsigned long long &x, unsigned long long y, unsigned long long w) {
  if ((double)y * w > 2e18)
    x += 2e18;
  else
    x += y * w;
  if (x > 2e18) x = 2e18;
}
int ff(int x) {
  if (to[x] != x) to[x] = ff(to[x]);
  return to[x];
}
void solve2(int l, int r, unsigned long long id) {
  d[l] = r;
  memset(to, 0, sizeof(to));
  memset(used, 0, sizeof(used));
  for (int i = l; i <= r; ++i) to[i] = i;
  to[l] = r;
  used[r] = 1;
  for (int i = l + 1; i <= r; ++i) {
    if (i == r) {
      for (int j = l; j <= r; ++j) {
        if (!used[j]) {
          d[i] = j;
          return;
        }
      }
    }
    unsigned long long w = p[max(r - i - 1, 0)];
    for (int j = l; j <= r; ++j) {
      if (!used[j] && ff(j) != i) {
        if (w < id)
          id -= w;
        else {
          to[i] = j;
          d[i] = j;
          used[j] = 1;
          break;
        }
      }
    }
  }
}
void solve(int i, int n, unsigned long long k) {
  if (i > n) return;
  for (int j = 0; j <= n - i; ++j) {
    unsigned long long w = 0;
    upd(w, f[n - i - j], p[max(j - 1, 0)]);
    if (k < w) {
      unsigned long long id = k / f[n - i - j] + 1;
      k %= f[n - i - j];
      solve2(i, i + j, id);
      solve(i + j + 1, n, k);
      return;
    } else
      k -= w;
  }
}
int main() {
  p[0] = 1;
  for (int i = 1; i <= 50; ++i) upd(p[i], p[i - 1], i);
  f[0] = 1;
  for (int i = 0; i < 50; ++i) {
    for (int j = 1; i + j <= 50; ++j) {
      upd(f[i + j], f[i], p[max(j - 2, 0)]);
    }
  }
  int t, n;
  long long k;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%lld", &n, &k);
    if (f[n] < k) {
      puts("-1");
      continue;
    }
    solve(1, n, k - 1);
    for (int i = 1; i <= n; ++i) printf("%d ", d[i]);
    puts("");
  };
  return 0;
}
