#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 20, MAXM = 54, SZ = 26;
const long long inf = 1e18 + 100, mod = 1e9 + 7;
long long dp[MAXM], cycle[MAXM];
long long mult(long long a, long long b) {
  long long c = a * b;
  if (max(a, b) >= inf || c >= inf) return inf;
  return c;
}
long long add(long long a, long long b) {
  long long c = a + b;
  if (max(a, b) >= inf || c >= inf) return inf;
  return c;
}
void init() {
  int n = 50;
  cycle[0] = cycle[1] = cycle[2] = 1;
  for (long long j = 3; j < 51; ++j) cycle[j] = mult(cycle[j - 1], (j - 2LL));
  dp[0] = 1;
  dp[1] = 1;
  for (long long j = 2; j < 51; ++j) {
    dp[j] = 0;
    for (int i = 1; i <= j; ++i) dp[j] = add(dp[j], mult(cycle[i], dp[j - i]));
  }
}
void solve() {
  long long n, k;
  cin >> n >> k;
  if (k > dp[n]) {
    cout << -1 << '\n';
    return;
  }
  vector<int> res(n, -1);
  vector<bool> us(n);
  for (int j = 0; j < n; ++j) {
    for (long long len = 1; len + j <= n; ++len) {
      long long cur = mult(cycle[len], dp[n - j - len]);
      if (cur < k) {
        k -= cur;
        continue;
      }
      res[j] = j + len - 1;
      us[j + len - 1] = true;
      for (int q = j + 1; q < j + len; ++q) {
        long long rest = len - 1 - (q - j);
        for (int nval = j; nval < j + len - 1; ++nval) {
          if (us[nval] || q == nval) continue;
          int tmp = res[nval];
          while (tmp != -1 && tmp != q) tmp = res[tmp];
          if (tmp != -1 && q != j + len - 1) continue;
          cur = mult(cycle[rest + 1], dp[n - j - len]);
          if (cur < k) {
            k -= cur;
            continue;
          }
          us[nval] = true;
          res[q] = nval;
          break;
        }
      }
      j += len - 1;
      break;
    }
  }
  for (int ri : res) cout << ++ri << ' ';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  init();
  int t = 1;
  cin >> t;
  while (t--) solve();
}
