#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1000;
const int MX = 55;
void add(long long& a, long long b) {
  a += b;
  if (a > INF) a = INF;
}
long long mult(long long a, long long b) {
  if (a <= INF / b) return a * b;
  return INF;
}
int ans[MX];
bool taken[MX];
long long cnt[MX];
long long dp[MX];
void solve() {
  memset(ans, 0, sizeof ans);
  memset(taken, 0, sizeof taken);
  int n;
  long long k;
  ignore = scanf("%d %lld", &n, &k);
  cnt[1] = cnt[2] = 1;
  for (int i = 3; i <= n; i++) cnt[i] = mult(i - 2, cnt[i - 1]);
  dp[n + 1] = 1;
  for (int i = n; i >= 1; i--) {
    dp[i] = 0;
    for (int len = 1; i + len - 1 <= n; len++) {
      add(dp[i], mult(cnt[len], dp[i + len]));
    }
  }
  if (dp[1] < k) {
    printf("-1\n");
    return;
  }
  for (int i = 1; i <= n;) {
    int len = 1;
    while (mult(cnt[len], dp[i + len]) < k) {
      k -= mult(cnt[len], dp[i + len]);
      len++;
    }
    ans[i] = i + len - 1;
    taken[i + len - 1] = true;
    for (int j = i + 1; j <= i + len - 1; j++) {
      int v = i;
      while (true) {
        if (taken[v]) {
          v++;
          continue;
        }
        if (j == i + len - 1) break;
        int t = v;
        while (ans[t]) t = ans[t];
        if (t == j) {
          v++;
          continue;
        }
        if (k > mult(dp[i + len], cnt[len - (j - i)])) {
          k -= mult(dp[i + len], cnt[len - (j - i)]);
          v++;
          continue;
        }
        break;
      }
      taken[v] = true;
      ans[j] = v;
    }
    i += len;
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  printf("\n");
}
int main() {
  int tests;
  ignore = scanf("%d", &tests);
  while (tests--) solve();
}
