#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int n, p;
    cin >> n >> p;
    for (int i = 0; i < n; ++i) {
      for (int j = max(0, i - 2); j < i; ++j)
        cout << i + 1 << " " << j + 1 << endl;
    }
    int edges = 2 * n - 3;
    if (edges == 2 * n + p) continue;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < i - 2; ++j) {
        cout << i + 1 << " " << j + 1 << endl;
        edges++;
        if (edges == 2 * n + p) break;
      }
      if (edges == 2 * n + p) break;
    }
  }
  return 0;
}
