#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5, OO = 1e14;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};
long long TC, n, m, k, a, b, c, cnt, u, mx, mn, ans, arr[N];
bool f, vis[N], mark[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> TC;
  while (TC--) {
    cin >> n >> m;
    cnt = f = 0;
    m += (2 * n);
    for (int i = 1; i <= n && !f; i++) {
      for (int j = i + 1; j <= n; j++) {
        cout << i << ' ' << j << '\n';
        if (++cnt == m) {
          f = 1;
          break;
        }
      }
    }
  }
  return 0;
}
