#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int m, p, cnt = 0;
    cin >> m >> p;
    for (int i = 1; i <= m; i++) {
      if (cnt > 2 * m + p) break;
      for (int j = i + 1; j <= m; j++) {
        cnt++;
        if (cnt > 2 * m + p) break;
        cout << i << ' ' << j << endl;
      }
    }
  }
}
