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