#include <bits/stdc++.h>
const int N = 50;
int t, n, m, k, p, a[N][N];
int main() {
  scanf("%d", &t);
  while (t--) {
    memset(a, 0, sizeof(a));
    scanf("%d%d", &n, &p);
    m = p % n;
    k = 3 + p / n;
    for (int i = 0; i < m; i++)
      for (int j = 1; j <= k; j++) a[i][(i + j) % n] = a[(i + j) % n][i] = 1;
    for (int i = m; i < n; i++)
      for (int j = 1; j < k; j++) a[i][(i + j) % n] = a[(i + j) % n][i] = 1;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++)
        if (a[i][j]) printf("%d %d\n", i + 1, j + 1);
  }
  return 0;
}
