#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int v, p;
    cin >> v >> p;
    int count = 2 * v + p;
    int cur = 0;
    for (int i = 1; i <= v; i++) {
      for (int j = i + 1; j <= v; j++) {
        if (cur == count) break;
        cout << i << " " << j << endl;
        cur++;
      }
      if (cur == count) break;
    }
  }
  return 0;
}
