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