#include <bits/stdc++.h>
using namespace std;
int n, p;
void solve() {
  int tot = 2 * n + p;
  vector<pair<int, int> > ans;
  for (int i = 1; i <= n; i++) {
    if (tot == 0) break;
    for (int j = i + 1; j <= n; j++) {
      ans.push_back(make_pair(i, j));
      tot--;
      if (tot == 0) break;
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d %d", &n, &p);
    solve();
  }
  return 0;
}
