#include <bits/stdc++.h>
using namespace std;
int t, n, p;
int g[25][25];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &p);
    memset(g, 0, sizeof g);
    for (int i = 1; i <= 5; i++) {
      for (int j = 1; j <= 5; j++) {
        g[i][j] = g[j][i] = 1;
      }
      g[i][i] = 0;
    }
    for (int i = 6; i <= n; i++) {
      int cnt = 0;
      for (int j = 1; j < i and cnt < 2; j++) {
        if (g[i][j] == 0) {
          g[i][j] = g[j][i] = 1;
          cnt++;
        }
      }
    }
    int cnt = 0;
    while (cnt < p) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (j != k and g[j][k] == 0) {
            g[j][k] = g[k][j] = 1;
            cnt++;
            k = j = n + 1;
          }
        }
      }
    }
    cnt = 2 * n + p;
    for (int i = 1; i <= n and cnt > 0; i++) {
      for (int j = i + 1; j <= n and cnt > 0; j++) {
        if (g[i][j] > 0) {
          printf("%d %d\n", i, j);
          cnt--;
        }
      }
    }
  }
  return 0;
}
