#include <bits/stdc++.h>
using namespace std;
bool vis[30][30];
vector<int> v[30];
int main() {
  int val, p, ts;
  cin >> ts;
  while (ts--) {
    cin >> val >> p;
    for (int i = 1; i <= val; i++) {
      for (int j = i + 1; j <= val; j++) {
        v[i].push_back(j);
      }
    }
    int sum = 0, extra = 0;
    while (1) {
      sum = 0;
      priority_queue<pair<int, int> > pq;
      for (int i = 1; i <= val; i++) {
        pq.push(make_pair(v[i].size(), i));
        sum += v[i].size();
      }
      if (sum == 2 * val + p) break;
      int u = pq.top().second;
      v[u].pop_back();
    }
    for (int i = 1; i <= val; i++) {
      for (int j = 0; j < v[i].size(); j++) cout << i << " " << v[i][j] << endl;
      v[i].clear();
    }
  }
}
