#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const long long INF = 2e18;
long long cycle[N];
inline long long add(long long a, long long b) {
  if (a > INF - b) return INF;
  return a + b;
}
inline long long mul(long long a, long long b) {
  if (b == 0) return 0;
  if (a > INF / b) return INF;
  return a * b;
}
void pre() {
  vector<long long> fact(N);
  fact[0] = fact[1] = 1;
  cycle[0] = cycle[1] = 1;
  for (int i = 2; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
    cycle[i] = fact[i - 2];
  }
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> dp(n + 2, 0);
  dp[n + 1] = 1;
  for (int i = n; i >= 1; i--) {
    for (int j = i; j <= n; j++) {
      dp[i] = add(dp[i], mul(dp[j + 1], cycle[j - i + 1]));
    }
  }
  if (dp[1] < k) {
    cout << -1 << '\n';
    return;
  }
  vector<bool> used(n + 1, false);
  vector<long long> ans(n + 1, -1);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      long long len = j - i + 1;
      long long contribution = mul(dp[j + 1], cycle[j - i + 1]);
      if (contribution < k) {
        k -= contribution;
        continue;
      }
      ans[i] = j;
      used[j] = true;
      for (int pos = i + 1; pos <= j; pos++) {
        for (int x = i; x <= j; x++) {
          if (used[x] or pos == x) continue;
          if (pos != j) {
            int cur = ans[x];
            while (cur != -1 and cur != pos) cur = ans[cur];
            if (cur == pos) continue;
          }
          long long contribution = mul(dp[j + 1], cycle[j - pos + 1]);
          if (contribution < k) {
            k -= contribution;
            continue;
          }
          ans[pos] = x;
          used[x] = true;
          break;
        }
      }
      i = j;
      break;
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  pre();
  int tc;
  cin >> tc;
  while (tc--) solve();
  return (0);
}
