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