#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
template <class T>
T sqr(T a) {
  return a * a;
}
int n, p;
void solve() {
  cin >> n >> p;
  int k = 2 * n + p;
  int m = 1;
  while (k) {
    for (int i = 0; i < n && k; ++i, --k) {
      int u = i;
      int v = ((i + m) % n);
      cout << u + 1 << " " << v + 1 << endl;
    }
    ++m;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
