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