#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, t, r, s, m, n, a, p, b, c, d, e, f, g, h;
  scanf("%d", &t);
  for (r = 0; r < t; r++) {
    scanf("%d %d", &n, &p);
    k = 2 * n + p;
    for (i = 1; i < n; i++) {
      for (j = i + 1; j <= n; j++) {
        if (k == 0) break;
        printf("%d %d\n", i, j);
        k--;
      }
      if (k == 0) break;
    }
  }
  return 0;
}
