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