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