#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, p;
    cin >> n >> p;
    long long edges = 2 * n + p;
    for (long long i = 1; i <= n && edges; i++) {
      for (long long j = i + 1; j <= n && edges; j++) {
        cout << i << " " << j << '\n';
        edges--;
      }
    }
  }
  return 0;
}
