#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
const int MAX_N = 55;
long long dp[MAX_N], cycle[MAX_N];
long long mult(long long a, long long b) {
  long double tmp = a;
  tmp *= b;
  if (tmp > INF) return INF;
  return a * b;
}
long long add(long long a, long long b) {
  long double tmp = a;
  tmp += b;
  if (tmp > INF) return INF;
  return a + b;
}
bool visited[MAX_N];
int ans[MAX_N];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    long long k;
    scanf("%d %lld", &n, &k);
    k--;
    dp[n] = 1;
    cycle[0] = cycle[1] = cycle[2] = 1;
    for (int i = 3; i <= n; i++) {
      cycle[i] = mult(cycle[i - 1], i - 2);
    }
    for (int i = n - 1; i >= 0; i--) {
      dp[i] = 0;
      for (int j = i; j < n; j++) {
        int size = j - i + 1;
        dp[i] = add(dp[i], mult(dp[j + 1], cycle[size]));
      }
    }
    if (k >= dp[0]) {
      printf("-1\n");
      continue;
    }
    memset(visited, 0, sizeof(visited));
    memset(ans, -1, sizeof(ans));
    for (int i = 0; i < n; i++) {
      for (int v = i; v < n; v++) {
        int sz = (v - i) + 1;
        long long cnt = mult(cycle[sz], dp[i + sz]);
        if (k >= cnt) {
          k -= cnt;
          continue;
        }
        ans[i] = v;
        visited[v] = true;
        for (int j = i + 1; j <= v; j++) {
          int sz2 = (v - j) + 1;
          for (int v2 = i; v2 < v; v2++) {
            if (v2 == j or visited[v2]) continue;
            if (j != v) {
              int tmp = ans[v2];
              while (tmp != -1 && tmp != j) {
                tmp = ans[tmp];
              }
              if (tmp == j) continue;
            }
            long long cnt2 = mult(cycle[sz2], dp[v + 1]);
            if (k >= cnt2) {
              k -= cnt2;
              continue;
            }
            ans[j] = v2;
            visited[v2] = true;
            break;
          }
        }
        i = v;
        break;
      }
    }
    for (int i = 0; i < n; i++) {
      printf("%d%c", ans[i] + 1, " \n"[i == n - 1]);
    }
  }
  return 0;
}
