#include <bits/stdc++.h>
const long long int M = 100005;
const long long int mod = 1000000007;
const double pi = acos(-1.0);
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  t = 1;
  cin >> t;
  while (t--) {
    long long int n, p;
    cin >> n >> p;
    long long int count = 0;
    bool done = false;
    for (long long int i = 1; i <= n; i++) {
      for (long long int j = i + 1; j <= n; j++) {
        cout << i << " " << j << "\n";
        count++;
        if (count == (2 * n + p)) {
          done = true;
          break;
        }
      }
      if (done) {
        break;
      }
    }
  }
}
