#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, T;
int main() {
  scanf("%d", &T);
  for (; T; T--) {
    scanf("%d%d", &n, &m);
    m += 2 * n;
    for (i = 1; i <= n; i++)
      for (j = i + 1; j <= n; j++)
        if (m) {
          m--;
          printf("%d %d\n", i, j);
        }
  }
  return 0;
}
