#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int inf = 1e9 + 7;
const long long linf = 1e18;
const double pi = acos(-1.0);
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  for (int total = 0; total < t; total++) {
    int n, p;
    cin >> n >> p;
    for (int temp = 0; temp < 2 * n + p;) {
      for (int i = 1; i <= n; i++) {
        if (temp == 2 * n + p) break;
        for (int j = i + 1; j <= n; j++) {
          temp++;
          cout << i << ' ' << j << endl;
          if (temp == 2 * n + p) break;
        }
      }
    }
  }
  return 0;
}
