#include <bits/stdc++.h>
using namespace std;
stringstream ss;
long long mod = 1000000007LL;
int mat[32][32];
int main() {
  for (int i = 1; i <= 25; i++)
    for (int j = i + 1; j <= 25; j++)
      if ((j - i) % 5 != 0) mat[i][j] = 1;
  int t, n, p;
  cin >> t;
  while (t--) {
    cin >> n >> p;
    int E = n + n + p;
    int i = 0, d = 1;
    while (E) {
      printf("%d %d\n", i % n + 1, (i + d) % n + 1), E--;
      if (++i == n) i = 0, d++;
    }
  }
  return 0;
}
