#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 7;
long long f[53], fac[53];
long long add(long long a, long long b) { return min(INF, a + b); }
long long mul(long long a, long long b) {
  if (INF / a < b) return INF;
  return a * b;
}
const int N = 50;
long long g(int n) {
  if (n == 1) return 1;
  return fac[n - 2];
}
void init() {
  fac[0] = 1;
  for (int i = 1; i <= N; i++) fac[i] = mul(fac[i - 1], i);
  f[0] = 1;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= i; j++) f[i] = add(f[i], mul(f[i - j], g(j)));
  return;
}
int p[53];
int q[53];
bool vis[53];
int find(int x) {
  while (q[x]) x = q[x];
  return x;
}
void getq(int n, long long k) {
  if (n == 1) {
    q[1] = 1;
    return;
  }
  for (int i = 1; i <= n; i++) q[i] = vis[i] = 0;
  q[1] = n;
  vis[n] = 1;
  for (int i = 2; i < n; i++) {
    long long num = fac[n - i - 1];
    for (int j = 1; j <= n; j++)
      if (j != i && !vis[j] && find(j) != i) {
        if (k <= num) {
          q[i] = j;
          vis[j] = true;
          break;
        }
        k -= num;
      }
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) q[n] = i;
  return;
}
void getp(int n, long long k) {
  if (!n) return;
  int len = 0;
  for (int i = 1; i <= n; i++) {
    long long num = mul(g(i), f[n - i]);
    if (k <= num) {
      len = i;
      break;
    }
    k -= num;
  }
  long long num = f[n - len];
  long long need = (k - 1) / num + 1;
  getp(n - len, k - (need - 1) * num);
  for (int i = n; i > len; i--) p[i] = p[i - len] + len;
  getq(len, need);
  for (int i = 1; i <= len; i++) p[i] = q[i];
  return;
}
int main() {
  init();
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    long long k;
    scanf("%d %lld", &n, &k);
    if (f[n] < k)
      printf("-1\n");
    else {
      getp(n, k);
      for (int i = 1; i <= n; i++) printf("%d ", p[i]);
      printf("\n");
    }
  }
  return 0;
}
