#include <bits/stdc++.h>
using namespace std;
const unsigned long long maxk = 1e18 + 1;
unsigned long long memo[55];
unsigned long long fact[55];
bitset<55> used;
int ans[55];
vector<int> DSU[2];
int tc, N;
unsigned long long K;
unsigned long long cnt(int u) { return u < 4 ? 1 : fact[u - 2]; }
unsigned long long mul(unsigned long long a, unsigned long long b) {
  long double at = a;
  long double bt = b;
  long double cap = maxk;
  if (a >= maxk || b >= maxk || cap <= a * b) {
    return maxk;
  }
  return a * b;
}
void initfact() {
  fact[0] = 1;
  for (int i = 1; i <= 50; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
}
unsigned long long dp(int len) {
  if (len <= 0) return 1;
  if (memo[len] != -1) return memo[len];
  unsigned long long res = 0;
  for (int i = 1; i <= len; i++) {
    unsigned long long C = mul(dp(len - i), cnt(i));
    if (C >= maxk) {
      return memo[len] = maxk;
    } else
      res += C;
    if (res >= maxk) return memo[len] = maxk;
  }
  return memo[len] = res;
}
void initdsu(int c) {
  for (int i = 1; i <= c; i++) {
    DSU[0][i] = i;
  }
}
int findpar(int u, int id) {
  return DSU[id][u] = (DSU[id][u] == u ? u : findpar(DSU[id][u], id));
}
void backtrack(int len, int now) {
  if (len == 0) return;
  unsigned long long res = 0;
  int F = 1;
  for (F = 1; F < len; F++) {
    unsigned long long C = mul(dp(len - F), cnt(F));
    if (K > C) {
      K -= C;
    } else
      break;
  }
  ans[now] = now + F - 1;
  for (int idx = 1 + now; idx <= ans[now]; idx++) {
    for (int cb = now; cb < ans[now]; cb++) {
      if ((findpar(idx, 0) == findpar(cb, 0)) || used[cb]) continue;
      unsigned long long C = 0;
      DSU[1] = DSU[0];
      DSU[1][findpar(idx, 1)] = findpar(cb, 1);
      for (int i = 1 + idx; i < ans[now]; i++) {
        if (DSU[1][i] == i) {
          C++;
        }
      }
      C = mul(fact[C], dp(len - F));
      if (K > C) {
        K -= C;
      } else {
        ans[idx] = cb;
        DSU[0][findpar(idx, 0)] = findpar(cb, 0);
        used[cb] = 1;
        break;
      }
    }
  }
  backtrack(len - F, now + F);
}
int main() {
  memset(memo, -1, sizeof memo);
  DSU[0].resize(55);
  DSU[1].resize(55);
  initfact();
  dp(50);
  scanf("%d", &tc);
  while (tc--) {
    scanf("%d %llu", &N, &K);
    if (dp(N) < K) {
      puts("-1");
      continue;
    }
    initdsu(N);
    used = 0;
    backtrack(N, 1);
    for (int i = 1; i <= N; i++) {
      printf("%d ", ans[i]);
    }
    putchar('\n');
  }
}
