#include <bits/stdc++.h>
using namespace std;
const int N = 100005, M = 1e5 + 5, OO = 0x3f3f3f3f;
vector<pair<int, int> > v;
int main() {
  int n, m, t, c = 0;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    int x = (2 * n) + m;
    for (int i = 1; i <= n; i++) {
      if (c > x) break;
      for (int j = i + 1; j <= n; j++) {
        if (c >= x) break;
        c++;
        cout << i << " " << j << endl;
      }
    }
    c = 0;
  }
  return 0;
}
