#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 1;
const long long N = 52;
long long mul(long long x, long long y) {
  if (x <= inf / y) {
    return x * y;
  }
  return inf;
}
long long add(long long x, long long y) {
  if (x + y >= inf) {
    return inf;
  }
  return x + y;
}
long long fact[N], dp[N], go[N], in[N];
bool used[N], used1[N];
long long count(vector<long long> pref, long long n) {
  long long i = 0;
  while (i < pref.size()) {
    if (pref[i] <= pref.size()) {
      i = pref[i];
    } else {
      break;
    }
  }
  if (i == pref.size()) {
    return dp[n - (long long)pref.size()];
  }
  for (long long j = i; j < pref.size(); j++) {
    if (pref[j] > pref[i]) {
      return 0;
    }
  }
  long long sz = pref[i] - i, cnt = 0;
  for (long long j = i; j < pref.size(); j++) {
    if (used1[j]) {
      continue;
    }
    long long k = j;
    while (true) {
      used1[k] = true;
      k = pref[k] - 1;
      if (k >= pref.size()) {
        cnt++;
        break;
      }
      if (k == j) {
        for (long long l = i; l < pref.size(); l++) {
          used1[l] = false;
        }
        return 0;
      }
      if (used1[k]) {
        break;
      }
    }
  }
  for (long long j = i; j < pref.size(); j++) {
    used1[j] = false;
  }
  return mul(dp[n - pref[i]], fact[sz - (pref.size() - i) - 1]);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, i, j, k, l, t, num;
  fact[0] = 1;
  for (i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
  dp[0] = 1;
  for (i = 1; i < N; i++) {
    for (j = 0; j <= i - 2; j++) {
      dp[i] = add(dp[i], mul(dp[j], fact[i - j - 2]));
    }
    dp[i] = add(dp[i], dp[i - 1]);
  }
  cin >> t;
  while (t--) {
    cin >> n >> num;
    num--;
    vector<long long> temp;
    for (i = 1; i <= n; i++) {
      used[i] = false;
    }
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        if (!used[j]) {
          temp.push_back(j);
          k = count(temp, n);
          if (num >= k) {
            num -= k;
            temp.pop_back();
          } else {
            used[j] = true;
            break;
          }
        }
      }
      if (temp.size() != i) {
        num = 1;
        break;
      }
    }
    if (!num && temp.size() == n) {
      for (i = 0; i < n; i++) {
        cout << temp[i] << ' ';
      }
      cout << '\n';
    } else {
      cout << "-1\n";
    }
  }
}
