#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 50;
const long long INF = 1000000000000000009ll;
long long fact[MAX_N + 9];
long long cnt[MAX_N + 9];
int nTest;
int n;
long long k;
int par[MAX_N + 9];
bool used[MAX_N + 9];
int ans[MAX_N + 9];
long long& GetFact(int id) { return fact[id + 1]; }
long long Plus(long long x, long long y) {
  if (x + y > INF) {
    return INF;
  }
  return x + y;
}
long long Mul(long long x, long long y) {
  if (x > INF / y) {
    return INF;
  }
  return x * y;
}
int GetPar(int x) {
  while (par[x] != x) {
    x = par[x];
  }
  return x;
}
int main() {
  GetFact(-1) = 1;
  GetFact(0) = 1;
  for (int i = 1; i <= MAX_N; i++) {
    GetFact(i) = Mul(GetFact(i - 1), i);
  }
  cnt[0] = 1;
  for (int i = 1; i <= MAX_N; i++) {
    cnt[i] = 0;
    for (int j = 1; j <= i; j++) {
      cnt[i] = Plus(cnt[i], Mul(GetFact(j - 2), cnt[i - j]));
    }
  }
  cin >> nTest;
  for (int iTest = 1; iTest <= nTest; iTest++) {
    cin >> n >> k;
    if (cnt[n] < k) {
      cout << "-1\n";
      continue;
    }
    for (int i = 1; i <= n; i++) {
      par[i] = i;
      used[i] = false;
    }
    long long tmp = 0;
    int i = 1;
    while (i <= n) {
      ans[i] = i;
      while (Plus(tmp, Mul(GetFact(ans[i] - i - 1), cnt[n - ans[i]])) < k) {
        tmp = Plus(tmp, Mul(GetFact(ans[i] - i - 1), cnt[n - ans[i]]));
        ans[i]++;
      }
      par[ans[i]] = i;
      used[ans[i]] = true;
      for (int j = i + 1; j <= ans[i] - 1; j++) {
        ans[j] = i;
        while (true) {
          if (!used[ans[j]] && ans[j] != GetPar(j)) {
            if (Plus(tmp, Mul(GetFact(ans[i] - j - 1), cnt[n - ans[i]])) < k) {
              tmp = Plus(tmp, Mul(GetFact(ans[i] - j - 1), cnt[n - ans[i]]));
            } else {
              break;
            }
          }
          ans[j]++;
        }
        par[ans[j]] = j;
        used[ans[j]] = true;
      }
      ans[ans[i]] = GetPar(ans[i]);
      used[ans[ans[i]]] = true;
      i = ans[i] + 1;
    }
    for (int i = 1; i <= n; i++) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
