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