#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, p;
    scanf("%d", &n);
    scanf("%d", &p);
    vector<pair<int, int> > ans;
    int edges = 2 * n + p;
    for (int i = int(1); i <= int(n); i++) {
      for (int j = int(i + 1); j <= int(n); j++) {
        if (edges) {
          ans.push_back(pair<int, int>(i, j));
          edges--;
        }
      }
    }
    for (vector<pair<int, int> >::iterator it = (ans).begin();
         it != (ans).end(); it++)
      printf("%d %d\n", it->first, it->second);
  }
  return 0;
}
