#include <bits/stdc++.h>
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
using namespace std;
const long long N = 2e5 + 77;
long long A[N];
void sol() {
  long long n, p;
  cin >> n >> p;
  long long g[n + 1][n + 1];
  memset(g, 0, sizeof(g));
  long long c = 2 * n + p;
  vector<pair<long long, long long> > Ans;
  for (long long(i) = (1); (i) < (n + 1); (i)++) {
    for (long long(j) = (1); (j) < (n + 1); (j)++) {
      if (i == j) continue;
      if (g[i][j] == 0 && c > 0) {
        g[i][j] = g[j][i] = 1;
        c--;
        Ans.push_back({i, j});
      }
    }
  }
  for (auto i : Ans) cout << i.first << ' ' << i.second << '\n';
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) sol();
  return 0;
}
