#include <bits/stdc++.h>
using namespace std;
const int N = 53;
const long long INF = 1e18;
template <typename T>
void read(T &x) {
  int ch = getchar();
  x = 0;
  bool f = false;
  for (; ch < '0' || ch > '9'; ch = getchar()) f |= ch == '-';
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  if (f) x = -x;
}
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) return a = b, 1;
  return 0;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) return a = b, 1;
  return 0;
}
int t, n, p[N], q[N];
long long k, f[N], fac[N];
bool vis[N];
long long add(long long a, long long b) { return min(a + b, INF); }
long long mul(long long a, long long b) {
  if (INF / a < b) return INF;
  return a * b;
}
long long g(int n) {
  if (n <= 1) return 1;
  return fac[n - 2];
}
int get(int x) {
  while (q[x]) x = q[x];
  return x;
}
void calcq(int n, long long k) {
  if (n == 1) {
    q[1] = 1;
    return;
  }
  for (int i = 1; i <= n; ++i) vis[i] = q[i] = 0;
  q[1] = n;
  vis[n] = true;
  for (int i = 2; i < n; ++i) {
    long long tmp = fac[n - i - 1];
    for (int j = 1; j <= n; ++j)
      if (j != i && !vis[j] && get(j) != i) {
        if (k <= tmp) {
          q[i] = j;
          vis[j] = true;
          break;
        }
        k -= tmp;
      }
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      q[n] = i;
      break;
    }
}
void calcp(int n, long long k) {
  if (!n) return;
  int len = 0;
  for (int i = 1; i <= n; ++i) {
    long long tmp = mul(g(i), f[n - i]);
    if (k <= tmp) {
      len = i;
      break;
    }
    k -= tmp;
  }
  long long num = f[n - len], grk = (k - 1) / num + 1;
  calcp(n - len, k - num * (grk - 1));
  for (int i = n - len; i; --i) p[i + len] = p[i] + len;
  calcq(len, grk);
  for (int i = 1; i <= len; ++i) p[i] = q[i];
}
int main() {
  read(t);
  fac[0] = f[0] = 1;
  for (int i = 1; i < N; ++i) fac[i] = mul(fac[i - 1], i);
  for (int i = 1; i < N; ++i)
    for (int j = 1; j <= i; ++j) f[i] = add(f[i], mul(g(j), f[i - j]));
  while (t--) {
    read(n);
    read(k);
    if (k > f[n]) {
      puts("-1");
      continue;
    }
    calcp(n, k);
    for (int i = 1; i <= n; ++i) printf("%d%c", p[i], " \n"[i == n]);
  }
}
