#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int mxn = 51;
long long n, k;
long long a[mxn], first[mxn], v[mxn], dp[mxn];
long long mul(long long x, long long y) { return x < inf / y ? x * y : inf; }
void answer() {
  cin >> n >> k;
  first[0] = first[1] = 1;
  for (int i = 2; i <= n; i++) first[i] = mul(i - 1, first[i - 1]);
  dp[n] = 1;
  for (int i = n - 1; ~i; i--) {
    a[i] = -1, v[i] = dp[i] = 0;
    for (int j = i; j < n; j++) {
      dp[i] = min(inf, dp[i] + mul(first[j - i], dp[j + 1]));
    }
  }
  if (k-- > dp[0]) {
    cout << -1 << '\n';
    return;
  }
  for (int i = 0, j; i < n; i++)
    for (int j = i; j < n; j++) {
      long long x = mul(first[j - i], dp[j + 1]);
      if (k >= x) {
        k -= x;
        continue;
      }
      v[a[i] = j] = 1;
      for (int l = i + 1; l <= j; l++)
        for (int p = i; p < j; p++)
          if (!v[p] && l != p) {
            if (j != l) {
              x = a[p];
              while (~x && x != l) x = a[x];
              if (x == l) continue;
            }
            x = mul(first[j - l], dp[j + 1]);
            if (k < x) {
              v[a[l] = p] = 1;
              break;
            }
            k -= x;
          }
      i = j;
      break;
    }
  cout << (a[0] + 1);
  for (int i = 1; i < n; i++) cout << " " << (a[i] + 1);
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) answer();
  return 0;
}
