#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, P, i, t, T, a, b;
  set<pair<int, int> > s;
  srand(1234);
  cin >> T;
  for (t = 0; t < T; t++) {
    cin >> N >> P;
    s.clear();
    s.insert(make_pair(1, 2));
    for (i = 3; i <= N; i++) {
      s.insert(make_pair(i - 1, i));
      s.insert(make_pair(i - 2, i));
    }
    while (s.size() < 2 * N + P) {
      a = rand() % N + 1;
      b = rand() % N + 1;
      if (a != b) s.insert(make_pair(min(a, b), max(a, b)));
    }
    for (set<pair<int, int> >::iterator it = s.begin(); it != s.end(); it++)
      cout << it->first << ' ' << it->second << endl;
  }
  return 0;
}
