#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 5;
const int N = 55;
long long mult(long long a, long long b) {
  if (a >= INF / b) return INF;
  return a * b;
}
long long add(long long a, long long b) { return min(INF, a + b); }
long long fact[N], dp[N];
int ans[N], v[N], p[N];
int main() {
  fact[0] = dp[0] = 1;
  for (int i = 1; i <= 50; i++) fact[i] = mult(fact[i - 1], 1LL * i);
  for (int i = 1; i <= 50; i++) {
    dp[i] = dp[i - 1];
    for (int j = 0; j < i - 1; j++)
      dp[i] = add(dp[i], mult(dp[j], fact[max(0, i - j - 2)]));
  }
  int T;
  cin >> T;
  while (T--) {
    int n;
    long long k;
    cin >> n >> k;
    if (dp[n] < k) {
      cout << "-1\n";
      continue;
    }
    for (int i = 1; i <= n; i++) {
      p[i] = i;
      v[i] = 1;
      ans[i] = 0;
    }
    int ind = 0;
    for (int i = 1; i <= n; i++) {
      int e = ans[ind + 1], pi = p[i];
      while (p[pi] != pi) pi = p[pi];
      for (int j = ind + 1; j <= n; j++) {
        if (ind + 1 == i) {
          long long r = mult(dp[n - j], fact[max(1, j - i - 1)]);
          if (k > r)
            k -= r;
          else {
            ans[i] = j;
            v[j] = 0;
            p[j] = i;
            if (i == j) ind++;
            break;
          }
        } else {
          if (i == j || !v[j] || (j == pi && i != e)) continue;
          long long r = mult(dp[n - e], fact[max(1, e - i - 1)]);
          if (k > r)
            k -= r;
          else {
            ans[i] = j;
            v[j] = 0;
            p[j] = i;
            if (i == e) ind = i;
            break;
          }
        }
      }
    }
    for (int i = 1; i <= n; i++) cout << ans[i] << " ";
    cout << "\n";
  }
}
