#include <bits/stdc++.h>
using namespace std;
int ans[51], t[51];
long long fac[51], dp[51];
bool vis[51];
const long long inf = 1e18 + 1;
long long mul(long long x, long long y) {
  if (inf / x > y) {
    return x * y;
  }
  return inf;
}
long long add(long long x, long long y) { return min(inf, x + y); }
int n;
long long k;
void fill(int l, int r) {
  for (int i = l; i <= r; i++) t[i] = i, vis[i] = 0;
  ans[l] = r, vis[r] = true;
  swap(t[l], t[r]);
  for (int i = l + 1; i <= r - 1; i++) {
    for (int j = l; j <= r; j++) {
      if (vis[j] || t[i] == j) continue;
      if (mul(fac[r - i - 1], dp[n - r]) >= k) {
        ans[i] = j;
        vis[j] = true;
        int x = t[i], y = t[j];
        t[y] = x, t[x] = y;
        break;
      } else
        k -= mul(fac[r - i - 1], dp[n - r]);
    }
  }
  ans[r] = t[r];
}
int main() {
  fac[0] = dp[0] = 1;
  for (int i = 1; i <= 50; i++) {
    fac[i] = mul(i, fac[i - 1]);
  }
  for (int i = 1; i <= 50; i++) {
    for (int j = 1; j <= i; j++) {
      dp[i] = add(dp[i], mul(dp[i - j], j - 2 >= 0 ? fac[j - 2] : 1));
    }
  }
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    if (dp[n] < k) {
      cout << "-1\n";
      continue;
    }
    int nw = 1;
    while (nw <= n) {
      for (int i = 1; i <= n - nw + 1; i++) {
        if (mul(i - 2 >= 0 ? fac[i - 2] : 1, dp[n - nw - i + 1]) >= k) {
          fill(nw, i + nw - 1);
          nw += i;
          break;
        } else {
          k -= mul(i - 2 >= 0 ? fac[i - 2] : 1, dp[n - nw - i + 1]);
        }
      }
    }
    for (int l = 1; l <= n; ++l) {
      cout << ans[l] << ' ';
    }
    cout << '\n';
  }
}
