#include <bits/stdc++.h>
using namespace std;
void smile() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int randomF() { return (rand() * RAND_MAX + rand()) % 1000000; }
int MOD = 1e9 + 7;
int mod(long long x) { return (x % MOD + MOD) % MOD; }
long long add(long long x, long long y) {
  x += y;
  while (x >= MOD) x -= MOD;
  while (x < 0) x += MOD;
  return x;
}
long long multipy(long long x, long long y) {
  return ((x % MOD) * (y % MOD)) % MOD;
}
int main() {
  smile();
  int t;
  cin >> t;
  while (t--) {
    int n, p;
    cin >> n >> p;
    for (int i = 1, cnt = 0; i <= n && cnt < 2 * n + p; ++i) {
      for (int j = i + 1; j <= n && cnt < 2 * n + p; ++j, cnt++) {
        cout << i << " " << j << '\n';
      }
    }
  }
}
