#include <bits/stdc++.h>
using namespace std;
int n;
long double fat[51], memo[51];
long double num_good_permutations(int x) {
  if (x > n) return 1;
  if (memo[x] != -1) return memo[x];
  long double ret = 0;
  for (int len = 1; x + len - 1 <= n; len++) {
    if (len == 1)
      ret += num_good_permutations(x + len);
    else
      ret += fat[len - 2] * num_good_permutations(x + len);
    if (ret >= ((long long)1e18 + 1)) break;
  }
  return memo[x] = ret;
}
int p[51], used[51];
int main() {
  fat[0] = 1;
  for (int i = 1; i < 51; i++) {
    fat[i] = min((long double)((long long)1e18 + 1), i * fat[i - 1]);
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    long long k;
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i++) {
      memo[i] = -1;
    }
    if (num_good_permutations(1) < k) {
      printf("-1\n");
      continue;
    }
    for (int i = 0; i <= n; i++) p[i] = 0;
    long double cnt = 0;
    int x = 1;
    while (x <= n) {
      int len = 1, max_value = x;
      while (max_value <= n) {
        long double tmp;
        if (len == 1) {
          tmp = num_good_permutations(x + len);
        } else {
          tmp = fat[len - 2] * num_good_permutations(x + len);
        }
        if (cnt + tmp >= k) break;
        cnt += tmp;
        len++;
        max_value++;
      }
      for (int i = x; i <= max_value; i++) {
        used[i] = false;
      }
      p[x] = max_value;
      used[max_value] = true;
      for (int i = x + 1; i <= max_value; i++) {
        int val = x;
        while (true) {
          if (used[val]) {
            val++;
            continue;
          }
          p[i] = val;
          if (i != max_value) {
            int j = val, visited = 1;
            while (j and j != i) {
              j = p[j];
            }
            if (j == i) {
              p[i] = 0;
              val++;
              continue;
            }
          }
          long double tmp;
          if (len - (i - x) == 1) {
            tmp = num_good_permutations(x + len);
          } else {
            tmp = fat[len - (i - x) - 2] * num_good_permutations(x + len);
          }
          if (cnt + tmp >= k) break;
          cnt += tmp;
          val++;
        }
        p[i] = val;
        used[val] = true;
      }
      x = max_value + 1;
    }
    for (int i = 1; i <= n; i++) {
      if (i > 1) printf(" ");
      printf("%d", p[i]);
    }
    printf("\n");
  }
}
