#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, t;
  cin >> t;
  while (t--) {
    cin >> n >> p;
    int e = 2 * n + p;
    for (int i = 1; i <= n && e; i++)
      for (int j = i + 1; j <= n && e; j++) {
        cout << i << " " << j << endl;
        e--;
      }
  }
  return 0;
}
