#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int total = 0;
  while (t--) {
    int n, p;
    cin >> n >> p;
    int limit = 2 * n + p;
    int edges = 0, diff = 1;
    while (edges < limit) {
      for (int i = 1; i + diff <= n && edges < limit; i++) {
        cout << i << ' ' << i + diff << '\n';
        edges++;
      }
      diff++;
    }
  }
}
