#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1e9;
const int N = 55;
int tc, n, ans[N];
long long k, cycle[N], cnt[N];
bool used[N];
long long mul(long long x, long long y) {
  if (x == 0) return 0;
  if (INF / x < y) return INF;
  return x * y;
}
long long add(long long x, long long y) { return min(x + y, INF); }
void block(int i, int j) {
  ans[i] = j;
  used[j] = 1;
  for (int l = i + 1; l <= j; l++) {
    for (int val = i; val <= j; val++) {
      if (!used[val] && val != l) {
        if (l != j) {
          int letak = val;
          while (letak != -1 && letak != l) {
            letak = ans[letak];
          }
          if (letak == l) continue;
        }
        int sisa = j - l + 1;
        long long cur = mul(cycle[sisa], cnt[j + 1]);
        if (cur <= k) {
          k -= cur;
          continue;
        }
        ans[l] = val;
        used[val] = 1;
        break;
      }
    }
  }
}
void solve() {
  cycle[0] = cycle[1] = cycle[2] = 1;
  for (int i = 3; i < N - 1; i++) {
    cycle[i] = mul(cycle[i - 1], i - 2);
  }
  cnt[n + 1] = 1;
  for (int i = n; i >= 1; i--) {
    cnt[i] = 0;
    for (int j = 1; j <= n - i + 1; j++) {
      cnt[i] = add(cnt[i], mul(cycle[j], cnt[i + j]));
    }
  }
  if (cnt[1] < k) {
    cout << -1 << '\n';
    return;
  }
  memset(ans, -1, sizeof(ans));
  memset(used, 0, sizeof(used));
  --k;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      int len = j - i + 1;
      long long cur = mul(cycle[len], cnt[j + 1]);
      if (cur <= k) {
        k -= cur;
        continue;
      }
      block(i, j);
      i = j;
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << (i + 1 <= n ? ' ' : '\n');
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    solve();
  }
  return 0;
}
