#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, p;
    bool f = true;
    cin >> n >> p;
    p += 4;
    for (int i = 1; i <= 2; i++)
      for (int j = 3; j <= n; j++) cout << i << " " << j << endl;
    if (p > 0) {
      p--;
      cout << "1 2" << endl;
    }
    for (int i = 3; i <= n - 1; i++) {
      if (p == 0) break;
      for (int j = i + 1; j <= n; j++) {
        if (p == 0) break;
        p--;
        cout << i << " " << j << endl;
      }
      if (p == 0) break;
    }
  }
  return 0;
}
