#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

int t, n, k;
vector<int> sides = {5, 7, 9, 11};
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    for(int cases = 0; cases < t; cases++)
    {
        cin >> n >> k;
        int need = n * n - 1 - k;
        vector<vector<int>> pos(n, vector<int>(4));
        for(int j = 0; j < 4; j++)
            pos[0][j] = ((n + 1) / 2) + (j * (n - 1));
        pos[0] = {};
        vector<pii> jumps;
        for(int i = n, layer = 0; i >= 3; i -= 2, layer++)
        {
            int taken = 0;
            for(int j = 0; j < 4; j++)
            {
                int save = 4 * i - sides[j] - 1;
                pos[layer + 1][j] = pos[layer][j] + save + 1;
                if(!taken && save > 0 && need >= save)
                {
                    need -= save;
                    jumps.push_back({pos[layer][j], pos[layer + 1][j]});
                    taken = 1;
                }
            }
        }
        assert(need >= 0);
        if(need == 0)
        {
            cout << "Case #" << (cases + 1) << ": " << jumps.size() << "\n";
            for(auto x : jumps)
                cout << x.first << " " << x.second << "\n";
        }
        else 
            cout << "Case #" << (cases + 1) << ": IMPOSSIBLE\n";
    }
    return 0;
}