#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long MOD = 1e9 + 7;
const double eps = 1e-9;
int n, p, t;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> p;
    int edges = 2 * n + p, done = false;
    set<pair<int, int> > already;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        int next = (j + i) % n;
        if (next == 0) next = n;
        if (already.find({min(j, next), max(j, next)}) != already.end())
          continue;
        cout << j << " " << next << "\n";
        already.insert({min(j, next), max(j, next)});
        edges--;
        if (edges <= 0) {
          done = true;
          break;
        }
      }
      if (done) break;
    }
  }
}
