#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    int n, p;
    cin >> n >> p;
    int f = 1, s = 1, prevs = 2;
    int x = 2 * n + p;
    while (x--) {
      s++;
      if (s > n) {
        f++, s = prevs + 1;
        prevs = s;
      }
      cout << f << " " << s << '\n';
    }
  }
  return 0;
}
