← Home
 #include <bits/stdc++.h>
using namespace std;
 
struct Cell {
    int x, y;
    int r, s;
};
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
 
        int cx = (n + 1) / 2;
        int cy = (m + 1) / 2;
 
        vector<Cell> cells;
        cells.reserve(n * m);
 
        for (int x = 1; x <= n; ++x) {
            for (int y = 1; y <= m; ++y) {
                int dx = abs(x - cx);
                int dy = abs(y - cy);
                cells.push_back({x, y, max(dx, dy), dx + dy});
            }
        }
 
        sort(cells.begin(), cells.end(), [](const Cell& a, const Cell& b) {
            if (a.r != b.r) return a.r < b.r;
            if (a.s != b.s) return a.s < b.s;
            if (a.x != b.x) return a.x < b.x;
            return a.y < b.y;
        });
 
        for (auto &c : cells) {
            cout << c.x << ' ' << c.y << '\n';
        }
    }
 
    return 0;
}