#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1E-6;
int main() {
  int T, Map[100][100], n, p;
  cin >> T;
  while (T--) {
    memset(Map, 0, sizeof Map);
    cin >> n >> p;
    int cnt = n * 2 + p;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (cnt == 0) break;
        cnt--;
        cout << i + 1 << ' ' << j + 1 << endl;
        Map[i][j] = 1;
      }
      if (!cnt) break;
    }
  }
  return 0;
}
