#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, p;
  cin >> n >> p;
  int k = n + n + p;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      if (k) {
        k--;
        cout << i << ' ' << j << '\n';
      }
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
