#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MAXN = 5 + 50;
constexpr ll INF = 1000000000000000002LL;
namespace dsu {
int f[MAXN], sz[MAXN];
void build(int n) {
  fill(sz, sz + n, 1);
  for (int i = (int)0; i < (int)n; ++i) f[i] = i;
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
bool join(int x, int y) {
  if ((x = find(x)) == (y = find(y))) return false;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  f[y] = x;
  return true;
}
bool connected(int i, int j) { return find(i) == find(j); }
}  // namespace dsu
ll memo[MAXN], f[MAXN];
int res[MAXN];
bitset<MAXN> used;
ll add(ll a, ll b) {
  if (a + b >= INF) return INF;
  return a + b;
}
ll mul(ll a, ll b) {
  long double ans = (long double)(a) * (long double)(b);
  if (ans >= INF) return INF;
  return a * b;
}
ll dp(int len) {
  ll& ans = memo[len];
  if (~ans) {
    assert(ans >= 0);
    return ans;
  }
  if (len == 0) return ans = 1;
  ans = 0;
  for (int i = 1; i <= len; ++i)
    ans = add(ans, mul(dp(len - i), f[max(0, i - 2)]));
  return ans;
}
void rebuild(int len, ll k, int pos, int n) {
  if (len == 0) {
    assert(pos == n);
    return;
  }
  ll ans = 0;
  for (int i = 1; i <= len; ++i) {
    ll ol = ans;
    ans = add(ans, mul(dp(len - i), f[max(0, i - 2)]));
    if (k <= ans) {
      k -= ol;
      ll j = k / dp(len - i);
      while (mul(j, dp(len - i)) < k) ++j;
      k -= mul(j - 1, dp(len - i));
      res[pos] = i + pos;
      dsu::build(MAXN);
      used.reset();
      for (int posin = 2; posin <= i; ++posin) {
        int put = -1;
        ll ac = 0, olac;
        for (int num = 1; num < i; ++num) {
          if (dsu::connected(num, posin) || used[num]) continue;
          olac = ac;
          ac = add(ac, f[max(0, i - posin - 1)]);
          if (j <= ac) {
            put = num;
            break;
          }
        }
        assert(put != -1);
        res[pos + posin - 1] = put + pos;
        used[put] = true;
        dsu::join(put, posin);
        j -= olac;
      }
      rebuild(len - i, k, i + pos, n);
      return;
    }
  }
  assert(false);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  f[0] = 1;
  for (int i = (int)1; i < (int)MAXN; ++i) {
    if (f[i - 1] == INF) {
      f[i] = f[i - 1];
    } else {
      f[i] = min(INF, 1LL * i * f[i - 1]);
    }
  }
  memset(memo, -1, sizeof memo);
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    ll k;
    cin >> n >> k;
    if (k <= dp(n)) {
      rebuild(n, k, 0, n);
      for (int i = (int)0; i < (int)n; ++i) cout << res[i] << ' ';
    } else {
      cout << -1;
    }
    cout << '\n';
  }
  return 0;
}
