#include <bits/stdc++.h>
int const N = 1e6;
using namespace std;
long long n, m, k, i, j, a, b, x, y, sum, ans;
long long arr[N], brr[N], crr[N], dp[N];
char st[N];
vector<long long> adj[101];
int main() {
  cin >> a;
  while (a--) {
    cin >> n >> m;
    b = 2 * n + m;
    long long flag = 1;
    for (i = 1; i <= n; i++) {
      for (j = i + 1; j <= n; j++) {
        if (b-- && flag) {
          cout << i << " " << j << endl;
        } else
          flag = 0;
      }
    }
  }
}
