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