#include <bits/stdc++.h>
const double pi = 3.1415926535897;
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, p, t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n >> p;
    int maxi = 2 * n + p;
    for (int u = 1; u <= n; u++) {
      for (int v = u + 1; v <= n; v++) {
        if (u == v) continue;
        if (maxi < 1) break;
        cout << u << " " << v << endl;
        maxi--;
      }
    }
  }
}
