#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int cases;
  scanf("%d", &cases);
  while (cases--) {
    int n, p;
    scanf("%d%d", &n, &p);
    for (int i = 2; i <= n; i++) {
      printf("%d %d\n", 1, i);
    }
    for (int i = 2; i < n; i++) {
      printf("%d %d\n", i, i + 1);
    }
    printf("%d %d\n", n, 2);
    int count = 0, extra = 2 * n + p - 2 * (n - 1);
    for (int i = 2; i <= n; i++) {
      for (int j = i + 2; j <= n; j++) {
        if (i == 2 && j == n) break;
        printf("%d %d\n", i, j);
        count++;
        if (count == extra) goto here;
      }
    }
  here:
    continue;
  }
  return 0;
}
