#include <bits/stdc++.h>
using namespace std;
int t;
int n, p;
int main() {
  scanf("%d", &t);
  for (int ttt = 1; ttt <= (t); ++ttt) {
    scanf("%d %d", &n, &p);
    int a = 1, b = 2;
    int cnt = 0;
    while (cnt < 2 * n + p) {
      printf("%d %d\n", a, b);
      if (b == n) {
        a++;
        b = a + 1;
      } else
        b++;
      cnt++;
    }
  }
  return 0;
}
