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