#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100, M = 20, LG = 30, base = 2;
const int MOD = 1e9 + 7, mod = 1e9 + 9;
const long long INF = 1e9, inf = 1e18;
long long t, n, p, a, b, k;
vector<long long> g[N];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> t;
  for (int e = 1; e <= t; e++) {
    cin >> n >> p;
    a = 1, b = 2, k = 2 * n + p;
    while (k > 0) {
      cout << a << " " << b << endl;
      b++, k--;
      if (b > n) a++, b = a + 1;
    }
  }
  return 0;
}
