#include <bits/stdc++.h>
using namespace std;
const int N = 50 + 1;
const long long inf = 2e18;
long long fact_2[N];
long long cnts[N][N];
long long decomps[N];
void init() {
  fact_2[0] = 1;
  fact_2[1] = 1;
  fact_2[2] = 1;
  for (int i = 3; i < 22; ++i) fact_2[i] = fact_2[i - 1] * (i - 2);
  for (int i = 22; i < N; ++i) fact_2[i] = inf;
  decomps[0] = 1;
  for (int i = 1; i < N; ++i) {
    cnts[i][1] = decomps[i - 1];
    decomps[i] += decomps[i - 1];
    for (int j = 2; j <= i; ++j) {
      if (decomps[i - j] >= 2 * inf / fact_2[j])
        cnts[i][j] = inf;
      else
        cnts[i][j] = decomps[i - j] * fact_2[j];
      decomps[i] += cnts[i][j];
      if (decomps[i] > inf) decomps[i] = inf;
    }
  }
}
int t;
int n;
long long k;
int p[N];
bool used[N];
void fill_p(int pos, int len, long long lex) {
  p[pos] = pos + len - 1;
  used[pos + len - 1] = true;
  for (int i = pos + 1; i < pos + len; ++i)
    for (int j = pos; j < pos + len - 1; ++j) {
      if (used[j]) continue;
      if (i == pos + len - 1) {
        p[i] = j;
        break;
      }
      int t = j;
      while (p[t] != -1) t = p[t];
      if (t == i) continue;
      if (lex < fact_2[len - i + pos]) {
        p[i] = j;
        used[j] = true;
        break;
      }
      lex -= fact_2[len - i + pos];
    }
}
bool fail;
void rec(int cnt) {
  if (cnt == 0) return;
  for (int i = 1; i <= cnt; ++i) {
    if (k < cnts[cnt][i]) {
      fill_p(n - cnt, i, k / decomps[cnt - i]);
      k %= decomps[cnt - i];
      rec(cnt - i);
      return;
    }
    k -= cnts[cnt][i];
  }
  fail = true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  init();
  cin >> t;
  while (t--) {
    cin >> n >> k;
    --k;
    for (int i = 0; i < n; ++i) {
      p[i] = -1;
      used[i] = false;
    }
    fail = false;
    rec(n);
    if (!fail) {
      for (int i = 0; i < n; ++i) cout << p[i] + 1 << ' ';
      cout << '\n';
    } else
      cout << "-1\n";
  }
}
