#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int i, j, k, l, m, n, p, q, r, t;
  cin >> t;
  while (t--) {
    cin >> n >> p;
    k = 2 * n + p;
    vector<vector<int> > adj;
    vector<int> *temp;
    for (i = 0; i <= n - 1; i++) {
      temp = new vector<int>;
      adj.push_back(*temp);
    }
    for (i = 0; i <= n - 1; i++) {
      adj[i].push_back(i + 1);
      adj[i].push_back(i + 2);
    }
    q = p / n;
    for (i = 0; i <= n - 1; i++) {
      for (j = 0; j <= q - 1; j++) adj[i].push_back(j);
    }
    r = p % n;
    for (i = 0; i <= r - 1; i++) {
      adj[i].push_back(0);
    }
    for (i = 0; i <= n - 1; i++) {
      j = adj[i].size();
      k = i + 1;
      for (l = i + 2; j != 0 && l <= n; l++) {
        cout << k << " " << l << endl;
        j--;
      }
      for (l = 1; l <= n && j != 0; l++) {
        cout << k << " " << l << endl;
        j--;
      }
    }
    adj.clear();
  }
  return 0;
}
