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