#include <bits/stdc++.h>
#include "testlib.h"
#include "common.h"

using ll = long long;

int main(int argc, char** argv) {
    registerGen(argc, argv, 1);

    int L = opt<int>("L");
    int R = opt<int>("R");

    struct Test {
        int n;
        std::vector<std::pair<int, int>> a;
        int cntX;
        int cntY;
    };
    std::vector<Test> tests;
    int sumN = 0;
    int testNum = 0;
    for (int n = 2; testNum < R; ++n) {
        std::vector<std::pair<int, int>> a;
        std::set<std::pair<int, int>> used;
        auto rec = [&](auto self, int i, int cntX, int cntY) -> void {
            if (testNum == R) {
                return;
            }
            if (i == n) {
                if (testNum >= L) {
                    tests.push_back({n, a, cntX, cntY});
                }
                testNum++;
                sumN += n;
                return;
            }
            for (int useX = 0; useX <= cntX; ++useX) {
                for (int useY = 0; useY <= cntY; ++useY) {
                    if (!used.emplace(useX, useY).second) {
                        continue;
                    }

                    a.emplace_back(useX, useY);

                    self(self, i + 1, cntX + (useX == cntX), cntY + (useY == cntY));

                    a.pop_back();

                    used.erase({useX, useY});
                }
            }
        };
        rec(rec, 0, 0, 0);
    }
    std::cout << tests.size() << "\n";
    for (auto [n, a, cntX, cntY] : tests) {
        std::cout << n << "\n";
        auto xs = genStrings(cntX);
        auto ys = genStrings(cntY);
        for (auto[i, j] : a) {
            std::cout << xs[i] << " " << ys[j] << "\n";
        }
    }

    return 0;
}
