#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
int n, m;
vector<pair<int, int> > ans;
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    ans.clear();
    cin >> n >> m;
    int k = 0;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) {
        if (k == (2 * n + m)) {
          i = n;
          break;
        }
        k++;
        ans.push_back(make_pair(i + 1, j + 1));
      }
    for (int i = 0; i < ans.size(); i++)
      cout << ans[i].first << ' ' << ans[i].second << endl;
  }
  return 0;
}
