#include <bits/stdc++.h>
using namespace std;
const int modul = 1000000007;
const int nmax = 10000;
const double e = 1e-8;
const double pi = acos(-1);
int n, m, stest, p;
int main() {
  ios::sync_with_stdio(false);
  for (cin >> stest; stest; stest--) {
    cin >> n >> p;
    p += 2 * n;
    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++) {
        if (p == 0) break;
        cout << i << " " << j << endl;
        p--;
      }
  }
  return 0;
}
