#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long int, long long int>;
using pii = pair<int, int>;
using pil = pair<int, long long int>;
using pli = pair<long long int, int>;
long long int d[109];
long long int f[109];
long long int c[109];
int a[109];
int b[109];
int n;
long long int m;
bool valid() {
  int i, j, k;
  int id = 0;
  for (i = 0; i < n; i++) {
    b[i] = 0;
  }
  for (i = 0; i < n; i++) {
    if (b[i] == 0) {
      id++;
      b[i] = id;
      j = a[i];
      int jmax = j;
      while (j != i) {
        b[j] = id;
        j = a[j];
        if (jmax < j) jmax = j;
      }
      if (jmax != a[i]) return false;
      for (k = i; k <= a[i]; k++) {
        if (b[k] != id) return false;
      }
    }
  }
  return true;
}
void inil() {
  int i, j, k;
  d[0] = 1;
  d[1] = 1;
  d[2] = 2;
  c[1] = 1;
  c[2] = 1;
  f[0] = 1;
  for (i = 1; i <= 99; i++) {
    f[i] = f[i - 1] * i;
  }
  for (i = 3; i <= 99; i++) {
    c[i] = f[i - 2];
  }
  for (i = 3; i <= 99; i++) {
    d[i] = 0;
    for (j = 1; j <= i; j++) {
      d[i] += c[j] * d[i - j];
    }
  }
}
int result[109];
int rl;
int p[109];
int get_p(int x) {
  if (p[x] == x) return x;
  return p[x] = get_p(p[x]);
}
void print_c(int n, int base, long long int m) {
  if (n == 1) {
    result[rl++] = base;
    return;
  }
  if (n == 2) {
    result[rl++] = base + 1;
    result[rl++] = base;
    return;
  }
  if (n == 3) {
    result[rl++] = base + 2;
    result[rl++] = base;
    result[rl++] = base + 1;
    return;
  }
  result[rl++] = base + n - 1;
  int i, j, k;
  for (i = 0; i < n; i++) {
    b[i] = 0;
    a[i] = -1;
    p[i] = i;
  }
  int bani;
  for (i = 1; i < n - 1; i++) {
    bani = get_p(i);
    for (j = 0;; j++) {
      if (j == bani) continue;
      if (b[j] == 1) continue;
      if (m <= f[n - i - 2]) break;
      m -= f[n - i - 2];
    }
    result[rl++] = base + j;
    b[j] = 1;
    p[j] = i;
  }
  {
    for (j = 0; j < n - 1; j++) {
      if (b[j] == 0) {
        result[rl++] = base + j;
        break;
      }
    }
  }
}
int main() {
  inil();
  int i, j, k;
  int t = 1, tv = 0;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %lld", &n, &m);
    if (n < 22 && m > d[n]) {
      printf("-1\n");
      continue;
    }
    int base = 0;
    rl = 0;
    while (n > 0) {
      if (n > 22) {
        result[rl++] = base + 1;
        base++;
        n--;
        continue;
      }
      for (i = 1; i < n; i++) {
        if (m <= c[i] * d[n - i]) {
          break;
        }
        m -= c[i] * d[n - i];
      }
      int size = i;
      print_c(size, base + 1, (m - 1) / d[n - size] + 1);
      m = (m - 1) % d[n - size] + 1;
      base += size;
      n -= size;
    }
    for (i = 0; i < rl; i++) printf("%d ", result[i]);
    printf("\n");
  }
}
