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