#include <bits/stdc++.h>
using namespace std;
long long const M = 1000000007;
double const pi = acos(-1);
long long const inf = 2e18;
long long const N = 200001;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, t;
  cin >> t;
  while (t--) {
    long long n, p, cnt = 0;
    cin >> n >> p;
    for (i = 1; i <= n; i++) {
      for (j = i + 1; j <= n; j++) {
        cout << i << " " << j << "\n";
        cnt++;
        if (cnt == (2 * n + p)) break;
      }
      if (cnt == (2 * n + p)) break;
    }
  }
  return 0;
}
