#include <bits/stdc++.h>
using namespace std;
void print(int a) { cout << a << " "; }
void print(long long a) { cout << a << " "; }
void print(double a) { cout << a << " "; }
void print(string a) { cout << a << " "; }
template <typename T1, typename T2>
void print(pair<T1, T2> a) {
  print(a.first);
  cout << " ::: ";
  print(a.second);
}
template <typename Container>
void print(const Container& c) {
  for (auto it = c.begin(); it != c.end(); it++) {
    print(*it);
  }
  cout << endl;
}
vector<long long> tot_comb(51, 0);
vector<long long> fac(51, 1);
int CALC_MAX = 0;
long long INF = 2e18;
long long get_fac(int x) {
  if (x <= 0) return 1;
  return fac[x];
}
long long mul(long long x, long long y) {
  if (x >= INF || y >= INF || x * y >= INF || x * y < 0) return INF;
  return x * y;
}
long long add(long long x, long long y) {
  if (x >= INF || y >= INF || x + y >= INF) return INF;
  return x + y;
}
void fill_fac() {
  fac[0] = 1;
  fac[1] = 1;
  for (int i = 2; i <= 50; i++) {
    fac[i] = mul(fac[i - 1], i);
  }
}
void fill_tot_comb() {
  tot_comb[0] = 1;
  tot_comb[1] = 1;
  tot_comb[2] = 2;
  tot_comb[3] = 4;
  for (int i = 4; i <= 50; i++) {
    tot_comb[i] = 0;
    for (int j = 1; j <= i; j++) {
      tot_comb[i] = add(tot_comb[i], mul(get_fac(j - 2), tot_comb[i - j]));
    }
  }
}
void KthPermhelp(int k, long long n, int st) {
  vector<int> perm(k + 1, 0);
  vector<int> pos(k + 1, 0);
  perm[1] = k;
  pos[k] = 1;
  long long cnt = n;
  vector<bool> taken(k + 1, false);
  taken[k] = true;
  for (int i = 2; i <= k; i++) {
    for (int j = 1; j < k; j++) {
      if (!taken[j]) {
        int jk = i;
        while (taken[jk]) jk = pos[jk];
        if (j == jk && i != k) continue;
        long long tot_with_j_i = get_fac(k - 1 - i);
        if (cnt > tot_with_j_i) {
          cnt -= tot_with_j_i;
        } else {
          perm[i] = j;
          taken[j] = true;
          pos[j] = i;
          break;
        }
      }
    }
  }
  if (k == 2) {
    perm[1] = 2;
    perm[2] = 1;
  }
  for (int i = 1; i <= k; i++) cout << perm[i] + st << " ";
}
void KthPerm(int n, long long k, int st) {
  if (n == 0) return;
  if (tot_comb[n] < k) {
    cout << -1;
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (mul(get_fac(i - 2), tot_comb[n - i]) >= k) {
      KthPermhelp(i, (k / tot_comb[n - i]) + (k % tot_comb[n - i] > 0), st);
      KthPerm(n - i,
              (k % tot_comb[n - i]) +
                  ((k % tot_comb[n - i] == 0) ? tot_comb[n - i] : 0),
              st + i);
      break;
    }
    k -= mul(get_fac(i - 2), tot_comb[n - i]);
  }
}
int main() {
  fill_fac();
  fill_tot_comb();
  int t;
  cin >> t;
  while (t--) {
    int n;
    long long int k;
    cin >> n >> k;
    KthPerm(n, k, 0);
    cout << endl;
  }
}
