#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 1;
int n, ans[51], t[51];
long long k, fac[51], dp[51];
bool v[51];
long long mul(long long x, long long y) {
  return !x ? 0 : inf / x < y ? inf : x * y;
}
long long cal(int x) { return x < 2 ? 1 : fac[x - 2]; }
void work(int l, int r) {
  for (auto i = (l); i <= (r); ++i) t[i] = i, v[i] = 0;
  ans[l] = r;
  v[r] = 1;
  swap(t[l], t[r]);
  for (auto i = (l + 1); i <= (r - 1); ++i) {
    for (auto j = (l); j <= (r); ++j)
      if (!v[j] && i != t[j]) {
        if (mul(fac[r - i - 1], dp[n - r]) >= k) {
          ans[i] = j;
          v[j] = 1;
          int x = t[i], y = t[j];
          t[x] = y;
          t[y] = x;
          break;
        } else
          k -= mul(fac[r - i - 1], dp[n - r]);
      }
  }
  ans[r] = t[r];
}
void sol() {
  scanf("%d%lld", &n, &k);
  if (dp[n] < k) return (void)printf("-1\n");
  int nw = 1;
  while (nw <= n)
    for (auto i = (1); i <= (n - nw + 1); ++i) {
      if (mul(cal(i), dp[n - nw - i + 1]) >= k) {
        work(nw, nw + i - 1);
        nw += i;
        break;
      } else
        k -= mul(cal(i), dp[n - nw - i + 1]);
    }
  for (auto i = (1); i <= (n); ++i) printf("%d%c", ans[i], i == n ? '\n' : ' ');
}
int main() {
  int t;
  fac[0] = 1;
  dp[0] = 1;
  for (auto i = (1); i <= (50); ++i) fac[i] = mul(fac[i - 1], i);
  for (auto i = (1); i <= (50); ++i)
    for (auto j = (1); j <= (i); ++j)
      dp[i] = min(inf, dp[i] + mul(dp[i - j], cal(j)));
  scanf("%d", &t);
  for (auto i = (1); i <= (t); ++i) sol();
}
