#include <bits/stdc++.h>
using namespace std;
int n, p, T;
bool edge[50][50];
int main() {
  scanf("%d", &T);
  while (T--) {
    memset(edge, false, sizeof edge);
    scanf("%d%d", &n, &p);
    edge[1][n] = edge[n][1] = true;
    for (int i = 1; i < n; ++i) edge[i][i + 1] = edge[i + 1][i] = true;
    if (n & 1) {
      for (int i = 1; i <= n; ++i) {
        int a = 1 + (i - 1) * 2, b = 1 + i * 2;
        a = (a - 1) % n + 1;
        b = (b - 1) % n + 1;
        edge[a][b] = edge[b][a] = true;
      }
    } else {
      for (int i = 1; i <= n / 2; ++i) {
        int a = 1 + (i - 1) * 2, b = 1 + i * 2;
        a = (a - 1) % n + 1;
        b = (b - 1) % n + 1;
        edge[a][b] = edge[b][a] = true;
      }
      for (int i = 1; i <= n / 2; ++i) {
        int a = 2 + (i - 1) * 2, b = 2 + i * 2;
        a = (a - 1) % n + 1;
        b = (b - 1) % n + 1;
        edge[a][b] = edge[b][a] = true;
      }
    }
    for (int i = 1; i <= n; ++i) {
      if (p && !edge[i][(i + n / 2 - 1) % n + 1]) {
        p--;
        edge[i][(i + n / 2 - 1) % n + 1] = edge[(i + n / 2 - 1) % n + 1][i] =
            true;
      }
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (i != j && p && !edge[i][j]) {
          edge[i][j] = edge[j][i] = true;
          p--;
        }
      }
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j < i; ++j) {
        if (edge[i][j]) {
          printf("%d %d\n", i, j);
        }
      }
    }
  }
}
