#include <bits/stdc++.h>
using namespace std;
long long frac[59], dp[59], a[59], fa[59];
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
void solve(int st, int i, long long k) {
  for (int j = 1; j <= i; j++) fa[j] = j;
  a[st] = st + i - 1;
  fa[1] = i;
  set<int> s;
  for (int j = 1; j < i; j++) s.insert(j);
  int l = s.size();
  for (int j = st + 1; j <= st + i - 1; j++) {
    l--;
    for (auto v : s) {
      if (l == 0) {
        a[j] = v + st - 1;
        break;
      }
      int f1 = getfa(v), f2 = getfa(j - st + 1);
      if (f1 == f2) continue;
      if (k > frac[l - 1])
        k -= frac[l - 1];
      else {
        fa[f1] = f2;
        a[j] = v + st - 1;
        s.erase(v);
        break;
      }
    }
  }
}
void dfs(int n, int st, long long k) {
  if (n == 0 || k == 0) return;
  if (k <= dp[n - 1] || n - 1 > 22) {
    a[st] = st;
    dfs(n - 1, st + 1, k);
  } else {
    k -= dp[n - 1];
    for (int i = 2; i <= n; i++)
      if (frac[i - 2] * dp[n - i] >= k) {
        long long tt, res;
        if (i == n)
          tt = k, res = 0;
        else {
          tt = k / dp[n - i] + 1, res = k % dp[n - i];
          if (res == 0) res = dp[n - i], tt--;
        }
        solve(st, i, tt);
        dfs(n - i, st + i, res);
        break;
      } else
        k -= frac[i - 2] * dp[n - i];
  }
}
int main() {
  frac[0] = 1;
  for (int i = 1; i <= 20; i++) frac[i] = frac[i - 1] * i;
  dp[0] = 1, dp[1] = 1;
  for (int i = 2; i <= 22; i++) {
    dp[i] = dp[i - 1];
    for (int j = 2; j <= i; j++) dp[i] += frac[j - 2] * dp[i - j];
  }
  int t, n;
  long long k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (n <= 22 && k > dp[n])
      cout << -1 << endl;
    else {
      dfs(n, 1, k);
      for (int i = 1; i <= n; i++) cout << a[i] << " ";
      cout << endl;
    }
  }
}
