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