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