#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, p;
    cin >> n >> p;
    long long int count = 0;
    for (long long int i = 0; i < n; i++) {
      bool flag = false;
      for (long long int j = i + 1; j < n; j++) {
        cout << i + 1 << " " << j + 1 << endl;
        count++;
        if (count == 2 * n + p) {
          flag = true;
          break;
        }
      }
      if (flag) {
        break;
      }
    }
  }
}
