#include <bits/stdc++.h>
int main() {
  int t, n, p;
  int a, i, j, k;
  while (scanf("%d", &t) != EOF) {
    for (i = 0; i < t; i++) {
      scanf("%d%d", &n, &p);
      a = 2 * n + p;
      for (j = 1; j < n; j++) {
        for (k = j + 1; k <= n && a; k++, a--) printf("%d %d\n", j, k);
      }
    }
  }
  return 0;
}
