#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int i, j, k, l, m, n, o, p, tot, b[100][100], t;
int x[N], y[N];
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> p;
    l = 0;
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) b[i][j] = 0;
    for (i = 1; i <= 5; i++)
      for (j = i + 1; j <= 5; j++) {
        x[++l] = i;
        y[l] = j;
        b[i][j] = 1;
      }
    for (i = 6; i <= n; i++) {
      x[++l] = 1;
      y[l] = i;
      x[++l] = 2;
      y[l] = i;
      b[1][i] = b[2][i] = 1;
    }
    for (i = 1; i <= n; i++)
      for (j = i + 1; j <= n; j++)
        if (p)
          if (!b[i][j]) {
            x[++l] = i;
            y[l] = j;
            b[i][j] = 1;
            p--;
          }
    for (i = 1; i <= l; i++) printf("%d %d\n", x[i], y[i]);
  }
  return 0;
}
