#include <bits/stdc++.h>   using namespace std;   void calc(int n, int p) {     int j = 1, k = 1;     int cnt = 0;     int here = 1;     for (int i = 0; i < 2 * n + p; i++) {       cout << j <<    ;       j += k;       if (j > n) j -= n;       cout << j << endl;       cnt++;       int tmp = j + k;       if (tmp > n) tmp -= n;       tmp += k;       if (tmp > n) tmp -= n;       if (j == here || tmp == j) {         if (cnt == n) {           cnt = 0;           k++;           j = 1;           here = 1;         } else {           j++;           here++;         }       }     }   }   int main() {     int t;     cin >> t;     vector<pair<int, int> > out;     for (int i = 0; i < t; i++) {       int n, p;       cin >> n >> p;       calc(n, p);     }     return 0;   }   