#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
void solve(int n, int p) {
  int req = 2 * n + p;
  queue<int> q;
  q.push(1);
  while (q.empty() == false) {
    int t = q.front();
    q.pop();
    for (int i = t + 1; i <= n; ++i) {
      req--;
      printf("%d %d\n", t, i);
      q.push(i);
      if (req == 0) {
        return;
      }
    }
  }
}
int main() {
  int test_case;
  scanf("%d", &test_case);
  while (test_case-- > 0) {
    int n, p;
    scanf("%d%d", &n, &p);
    solve(n, p);
  }
  return 0;
}
