#include <bits/stdc++.h>
#define PII pair<int, int>
using namespace std;

vector<PII> getTestCase(int n, int r) {

    if(n < r) {
        vector<PII> ans;
        vector<int> p(n, 0);
        for(int i = 0; i < n; ++i)
            p[i] = i + 1;
        random_shuffle(p.begin(), p.end());
        for(int i = 0; i < n - 1; ++i) 
            ans.push_back(make_pair(p[i], p[i + 1]));
        //for(int i = 0; i < n - 1; ++i)
            //ans.push_back(make_pair(p[i], p[i + 1 + rand() % (n - 1 - i)]));
        return ans;
    }

    int firstSize = n / r;
    int secondSize = n - firstSize;

    vector<PII> firstPart = getTestCase(firstSize, r);
    vector<PII> secondPart = getTestCase(secondSize, r);
    
    for(auto &tmp : secondPart) {
        tmp.first += firstSize;
        tmp.second += firstSize;
    }

    vector<PII> ans;
    
    int firstPartEdges = firstPart.size();
    int secondPartEdges = secondPart.size();

    for(int it1 = 0, it2 = 0; it1 < firstPartEdges || it2 < secondPartEdges;) {
        if(it1 == firstPartEdges)
            ans.push_back(secondPart[it2++]);
        else if(it2 == secondPartEdges)
            ans.push_back(firstPart[it1++]);
        else {
            if(rand() % 2) 
                ans.push_back(firstPart[it1++]);
            else
                ans.push_back(secondPart[it2++]);
            }
    }

    set<PII> has;
    for(int i = 0; i < min(10LL, 1LL * firstSize * secondSize); ++i) {
        pair<int, int> now = make_pair(-1, -1);
        do {
            int a = rand() % firstSize + 1;
            int b = rand() % secondSize + 1 + firstSize;
            if(rand() % 2)
                now = make_pair(a, b);
            else
                now = make_pair(b, a);
        } while(has.find(now) != has.end());
        has.insert(now);
        ans.push_back(now);
    }

    return ans;
}

const int n[5] = {1000, 1000, 100000, 100000, 100000};
const int r[5] = {100, 10, 10, 1000, 10000}; 

int main() {
    srand(time(0));
    ofstream cout("grader_test1.in");

    cout << 5 << "\n";
    for(int i = 0; i < 5; ++i) {
        vector<PII> graph = getTestCase(n[i], r[i]);
        int m = graph.size();
        cout << n[i] << " " << m << "\n";
        for(auto tmp : graph)
            cout << tmp.first << " " << tmp.second << "\n";
    }
}
