#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int v[100000];
  int wjm[1000][1000];
  for (int i = 0; i < t; ++i) {
    int n, p;
    cin >> n >> p;
    memset(v, 0, sizeof(v));
    memset(wjm, 0, sizeof(wjm));
    vector<pair<int, int> > cute;
    for (int i = 0; i < 2 * n + p; ++i) {
      pair<int, int> m1 = {1e9, 0};
      pair<int, int> m2 = {1e9, 0};
      for (int j = 0; j < n; ++j) {
        if (v[j] < m1.first) {
          m1 = {v[j], j};
        }
      }
      for (int j = 0; j < n; ++j) {
        if (j != m1.second && !wjm[m1.second][j]) {
          if (v[j] < m2.first) {
            m2 = {v[j], j};
          }
        }
      }
      cute.push_back({m1.second, m2.second});
      wjm[m1.second][m2.second] = 1;
      wjm[m2.second][m1.second] = 1;
      ++v[m1.second];
      ++v[m2.second];
    }
    for (auto x : cute) {
      cout << x.first + 1 << ' ' << x.second + 1 << '\n';
    }
  }
}
