#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  std ::ios_base ::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, p;
    cin >> n >> p;
    int edges = 2 * n + p;
    bool flag = true;
    for (int i = 1; i <= n; ++i) {
      for (int j = i + 1; j <= n; ++j) {
        cout << i << " " << j << endl;
        edges--;
        if (edges == 0) {
          flag = false;
          break;
        }
      }
      if (!flag) break;
    }
  }
}
