#include <bits/stdc++.h>
using namespace std;
int mat[30][30];
int t, n, p;
int main() {
  scanf("%d", &t);
  for (int cas = 1; cas < t + 1; ++cas) {
    memset(mat, 0, sizeof mat);
    scanf("%d %d", &n, &p);
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        printf("%d %d\n", i + 1, j + 1);
        mat[i][j] = mat[j][i] = true;
        cnt++;
        if (cnt == 2 * n + p) goto sai;
      }
    }
  sai:;
  }
  return 0;
}
