#include <bits/stdc++.h>
using namespace std;
const int oo = 50;
int t, n, p;
int main() {
  cin >> t;
  for (int ip = 0; ip < t; ip++) {
    cin >> n >> p;
    int e = 0, x = 1, y = 1;
    vector<int> ans;
    while (e < 2 * n + p) {
      y = x + 1;
      while (e < 2 * n + p && y <= n) {
        ans.push_back(x);
        ans.push_back(y);
        e++;
        y++;
      }
      x++;
    }
    for (int i = 0; i < ans.size(); i += 2)
      cout << ans[i] << ' ' << ans[i + 1] << endl;
  }
  return 0;
}
