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