#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, std::vector<long long>, std::greater<long long> > pqs;
queue<long long> q;
stack<long long> sta;
set<long long> st;
set<long long>::iterator P;
long long i, j, n, m, t, k, a, b, c, x, mx, mn;
string s, s1;
char z;
vector<pair<long long, long long> > v;
map<pair<long long, long long>, long long> mp, pm;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int T = 1;
  cin >> T;
  while (T--) {
    i = j = n = m = t = k = a = b = c = x = mx = mn = 0;
    cin >> n >> m;
    m += 2 * n;
    for (i = 1; i <= n && m; i++)
      for (j = i + 1; j <= n && m; j++) cout << i << ' ' << j << endl, m--;
  }
  return 0;
}
