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