#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int t, n, p, x, y;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> p;
    x = 2 * n + p;
    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++) {
        if (x == 0) break;
        cout << i << " " << j << endl;
        x--;
      }
  }
  return 0;
}
