#include <bits/stdc++.h>
using namespace std;
const int N = 50 + 1;
const long long lim = (long long)(1e18) + 5, oo = 3e18;
vector<long long> fact(3, 1), dp(N, -1);
long long mul(long long a, long long b) {
  if (lim / a <= b) return oo;
  a *= b;
  if (a >= lim) return oo;
  return a;
}
long long add(long long a, long long b) {
  a += b;
  if (a >= lim) return oo;
  return a;
}
long long calc(int a) {
  if (a == 0) return 1;
  if (dp[a] != -1) return dp[a];
  dp[a] = 0;
  for (int i = 1; i <= a; i++) dp[a] = add(dp[a], mul(calc(a - i), fact[i]));
  return dp[a];
}
vector<int> ans;
int chainBase[N], baseofChain[N];
void dodaj(int offset, int vel, long long k) {
  ans.push_back(vel + offset);
  for (int i = 0; i < vel; i++) chainBase[i] = baseofChain[i] = i;
  vector<bool> taken(vel);
  for (int i = 1; i < vel; i++)
    for (int j = 0; j < vel - 1; j++)
      if (!taken[j] && chainBase[i] != j) {
        if (k <= fact[vel - i]) {
          ans.push_back(offset + j + 1);
          baseofChain[chainBase[i]] = baseofChain[j];
          chainBase[baseofChain[j]] = chainBase[i];
          taken[j] = 1;
          break;
        }
        k -= fact[vel - i];
      }
}
int n;
void gen(int a, long long k) {
  if (a == 0) return;
  for (int i = 1; i <= a; i++) {
    long long drugo = calc(a - i);
    long long imam = mul(drugo, fact[i]);
    if (imam >= k) {
      long long koliko = (k - 1) / drugo;
      dodaj(n - a, i, koliko + 1);
      k -= koliko * drugo;
      gen(a - i, k);
      return;
    }
    k -= imam;
  }
}
int main() {
  for (int i = 1; i < N; i++) fact.push_back(mul(fact.back(), i));
  int t;
  scanf("%i", &t);
  while (t--) {
    long long k;
    scanf("%i %lld", &n, &k);
    if (calc(n) < k) {
      printf("-1\n");
      continue;
    }
    ans.clear();
    gen(n, k);
    for (auto p : ans) printf("%i ", p);
    printf("\n");
  }
  return 0;
}
