#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int inf = 1e9 + 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, p;
    cin >> n >> p;
    int l = 2 * n + p;
    for (int i = 1; i < n; i++) {
      for (int j = i + 1; j <= n && l > 0; j++, l--) {
        cout << (i) << " " << (j) << '\n';
      }
    }
  }
  return 0;
}
