#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int t;
    in >> t;
    while (t--) {
      int n, p;
      in >> n >> p;
      int cnt_r = 0;
      vector<pair<int, int>> ans;
      for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
          if (cnt_r == 2 * n + p) {
            break;
          } else {
            ans.push_back({i, j});
            cnt_r++;
          }
        }
        if (cnt_r == 2 * n + p) {
          break;
        }
      }
      for (int i = 0; i < ans.size(); i++) {
        out << ans[i].first << " " << ans[i].second << endl;
      }
    }
  }
};
void solve(std::istream& in, std::ostream& out) {
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream& in = cin;
  ostream& out = cout;
  solve(in, out);
  return 0;
}
