/*
#include <sys/stat.h>
#include <unistd.h>
 * Strong test generator for Task GT13: WAREHOUSE (СКЛАД)
 *
 * Subtask 1: n, q <= 2000,    a[i] <= 100000
 * Subtask 2: n, q <= 20000,   a[i] <= 100000
 * Subtask 3: n, q <= 100000,  all queries l=1
 * Subtask 4: n, q <= 100000,  a[i] <= 100
 * Subtask 5: n, q <= 100000,  no extra constraints
 *
 * 10 tests per subtask, each targeting specific corner cases.
 *
 * Compile: g++ -O2 -o gen gen.cpp
 * Run:     ./gen
 */

#include <bits/stdc++.h>
#include <sys/stat.h>
#include <sys/stat.h>
using namespace std;

mt19937 rng(1337);

int randInt(int lo, int hi) {
    return uniform_int_distribution<int>(lo, hi)(rng);
}

// ─────────────────────────────────────────────
//  Array builders
// ─────────────────────────────────────────────

// Random array, values in [1, maxVal]
vector<int> arrRandom(int n, int maxVal) {
    vector<int> a(n);
    for (auto& x : a) x = randInt(1, maxVal);
    return a;
}

// All same value v
vector<int> arrAllSame(int n, int v) {
    return vector<int>(n, v);
}

// Exactly x copies of x for several x values, rest filled with large values (> n)
// Makes many "valid" labels; wrong solutions that skip the count==value check fail.
vector<int> arrManyValid(int n, int maxVal) {
    vector<int> a;
    for (int x = 1; x * x <= n && (int)a.size() + x <= n; x++)
        for (int j = 0; j < x; j++) a.push_back(x);
    // filler: values strictly > n so they can never be valid (need >n occurrences)
    int fillerLo = n + 1;
    int fillerHi = max(fillerLo, maxVal); // guarantee lo <= hi
    while ((int)a.size() < n) a.push_back(randInt(fillerLo, fillerHi));
    shuffle(a.begin(), a.end(), rng);
    return a;
}

// "Almost valid": x appears x-1 or x+1 times — must NOT count
vector<int> arrAlmostValid(int n, int maxVal) {
    maxVal = max(maxVal, n + 1); // ensure we can always fill with large values
    vector<int> a;
    for (int x = 2; x <= 20 && (int)a.size() + x <= n; x++) {
        int cnt = (randInt(0, 1) ? x - 1 : x + 1);
        cnt = max(1, min(cnt, n - (int)a.size()));
        for (int j = 0; j < cnt; j++) a.push_back(x);
    }
    while ((int)a.size() < n) a.push_back(randInt(1, maxVal));
    shuffle(a.begin(), a.end(), rng);
    return a;
}

// Permutation of 1..n — every element appears exactly once → label x=1 valid everywhere
vector<int> arrPermutation(int n) {
    vector<int> a(n);
    iota(a.begin(), a.end(), 1);
    shuffle(a.begin(), a.end(), rng);
    return a;
}

// All values > n → answer always 0
vector<int> arrAllLarge(int n, int maxVal) {
    int lo = n + 1;
    int hi = max(lo, maxVal); // clamp so lo <= hi always
    vector<int> a(n);
    for (auto& x : a) x = randInt(lo, hi);
    return a;
}

// Small values only (for subtask 4 style), lots of repeats
vector<int> arrSmallVals(int n, int maxVal) {
    vector<int> a(n);
    for (auto& x : a) x = randInt(1, maxVal);
    return a;
}

// Blocks: positions 1..1 have value 1, positions 2..3 have value 2, etc.
// Sliding window across blocks changes valid count sharply.
vector<int> arrBlocks(int n) {
    vector<int> a;
    for (int x = 1; (int)a.size() < n; x++) {
        int cnt = min(x, n - (int)a.size());
        for (int j = 0; j < cnt; j++) a.push_back(x);
    }
    return a;
}

// Valid labels placed exactly at query boundaries.
// Value k appears exactly k times, grouped, no padding.
vector<int> arrBoundaryValid(int n) {
    vector<int> a(n, 999999);
    int pos = 0;
    for (int k = 1; pos + k <= n; k++) {
        for (int j = 0; j < k; j++) a[pos + j] = k;
        pos += k;
    }
    return a;
}

// ─────────────────────────────────────────────
//  Query builders
// ─────────────────────────────────────────────

vector<pair<int,int>> qFull(int n, int q) {
    return vector<pair<int,int>>(q, {1, n});
}

vector<pair<int,int>> qSingle(int n, int q) {
    vector<pair<int,int>> qs(q);
    for (auto& [l, r] : qs) l = r = randInt(1, n);
    return qs;
}

vector<pair<int,int>> qPrefixes(int n, int q) {
    vector<pair<int,int>> qs(q);
    for (auto& [l, r] : qs) { l = 1; r = randInt(1, n); }
    return qs;
}

vector<pair<int,int>> qRandom(int n, int q) {
    vector<pair<int,int>> qs(q);
    for (auto& [l, r] : qs) {
        l = randInt(1, n); r = randInt(1, n);
        if (l > r) swap(l, r);
    }
    return qs;
}

// Short queries (length 1..10) — stress boundary conditions
vector<pair<int,int>> qShort(int n, int q) {
    vector<pair<int,int>> qs(q);
    for (auto& [l, r] : qs) {
        l = randInt(1, n);
        r = min(n, l + randInt(0, 9));
    }
    return qs;
}

// Sliding window of fixed length ~n/3 — one element enters, one leaves each step
vector<pair<int,int>> qSliding(int n, int q) {
    vector<pair<int,int>> qs;
    int len = max(1, n / 3);
    for (int l = 1; l + len - 1 <= n && (int)qs.size() < q; l++)
        qs.push_back({l, l + len - 1});
    while ((int)qs.size() < q) {
        int l = randInt(1, n), r = randInt(l, n);
        qs.push_back({l, r});
    }
    return qs;
}

// Tiny queries (length 1-2) — large x values cannot be valid
vector<pair<int,int>> qTiny(int n, int q) {
    vector<pair<int,int>> qs(q);
    for (auto& [l, r] : qs) {
        l = randInt(1, n);
        r = min(n, l + 1);
    }
    return qs;
}

// All suffix queries [l, n]
vector<pair<int,int>> qSuffixes(int n, int q) {
    vector<pair<int,int>> qs;
    for (int l = 1; l <= n; l++) qs.push_back({l, n});
    while ((int)qs.size() < q) {
        int l = randInt(1, n), r = randInt(l, n);
        qs.push_back({l, r});
    }
    qs.resize(q);
    return qs;
}

// ─────────────────────────────────────────────
//  Write test
// ─────────────────────────────────────────────

void writeTest(const string& filename,
               const vector<int>& a,
               const vector<pair<int,int>>& qs) {
    if (filename.empty()) return;
    FILE* f = fopen(filename.c_str(), "w");
    if (!f) { cerr << "Cannot open " << filename << "\n"; exit(1); }
    // small 64KB buffer — keeps memory footprint low across many tests
    static char buf[65536];
    setvbuf(f, buf, _IOFBF, sizeof(buf));
    int n = (int)a.size(), q = (int)qs.size();
    fprintf(f, "%d %d\n", n, q);
    for (int i = 0; i < n; i++)
        fprintf(f, i+1==n ? "%d\n" : "%d ", a[i]);
    for (auto [l, r] : qs)
        fprintf(f, "%d %d\n", l, r);
    fclose(f);
    cerr << "  -> " << filename << "  (n=" << n << " q=" << q << ")\n";
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    mkdir("tests", 0755);

    int first = 1, last = 9999;
    if (argc >= 2) first = atoi(argv[1]);
    if (argc >= 3) last  = atoi(argv[2]);

    int idx = 1;
    // need(): should we generate the current test?
    auto need = [&]() -> bool {
        return idx >= first && idx <= last;
    };
    auto fn = [&]() -> string {
        int cur = idx++;
        if (cur > last) { exit(0); }   // all done — stop immediately
        if (cur < first) return "";    // before range — skip write but still build
        char buf[64];
        snprintf(buf, sizeof(buf), "tests/task%02d.in", cur);
        return string(buf);
    };

    // ══════════════════════════════════════════════
    //  SUBTASK 1  n,q <= 2000
    // ══════════════════════════════════════════════
    cerr << "\n[Subtask 1] n,q <= 2000\n";
    int N1 = 1000, Q1 = 1000;

    // T01: All same value = n → valid only if entire array is queried
    if (need()) { auto _a=arrAllSame(N1, N1); auto _q=qRandom(N1, Q1); writeTest(fn(),_a,_q); } else { idx++; }

    // T02: All same value = 1 → count>=1 always, valid only if count==1 (never for len>1)
    if (need()) { auto _a=arrAllSame(N1, 1); auto _q=qRandom(N1, Q1); writeTest(fn(),_a,_q); } else { idx++; }

    // T03: Permutation 1..n → value 1 is always valid in any query containing it
    if (need()) { auto _a=arrPermutation(N1); auto _q=qRandom(N1, Q1); writeTest(fn(),_a,_q); } else { idx++; }

    // T04: All values > n → answer always 0
    if (need()) { auto _a=arrAllLarge(N1, 100000); auto _q=qRandom(N1, Q1); writeTest(fn(),_a,_q); } else { idx++; }

    // T05: Many valid labels planted, random queries
    if (need()) { auto _a=arrManyValid(N1, 100000); auto _q=qRandom(N1, Q1); writeTest(fn(),_a,_q); } else { idx++; }

    // T06: Almost valid labels — x appears x±1 times, must return 0 for those
    if (need()) { auto _a=arrAlmostValid(N1, 100000); auto _q=qRandom(N1, Q1); writeTest(fn(),_a,_q); } else { idx++; }

    // T07: Block structure + sliding window — valid labels enter/leave one by one
    if (need()) { auto _a=arrBlocks(N1); auto _q=qSliding(N1, Q1); writeTest(fn(),_a,_q); } else { idx++; }

    // T08: Boundary valid + suffix queries — valid label sits exactly at boundary
    if (need()) { auto _a=arrBoundaryValid(N1); auto _q=qSuffixes(N1, Q1); writeTest(fn(),_a,_q); } else { idx++; }

    // T09: Single-element queries — only x=1 can ever be valid
    if (need()) { auto _a=arrRandom(N1, N1); auto _q=qSingle(N1, Q1); writeTest(fn(),_a,_q); } else { idx++; }

    // T10: Full-array queries only — stress total counting
    if (need()) { auto _a=arrManyValid(N1, 100000); auto _q=qFull(N1, Q1); writeTest(fn(),_a,_q); } else { idx++; }

    // ══════════════════════════════════════════════
    //  SUBTASK 2  n,q <= 20000
    // ══════════════════════════════════════════════
    cerr << "\n[Subtask 2] n,q <= 20000\n";
    int N2 = 20000, Q2 = 20000;

    // T11: All same value
    if (need()) { auto _a=arrAllSame(N2, N2); auto _q=qRandom(N2, Q2); writeTest(fn(),_a,_q); } else { idx++; }

    // T12: Permutation — x=1 always valid
    if (need()) { auto _a=arrPermutation(N2); auto _q=qRandom(N2, Q2); writeTest(fn(),_a,_q); } else { idx++; }

    // T13: All large → always 0
    if (need()) { auto _a=arrAllLarge(N2, 100000); auto _q=qRandom(N2, Q2); writeTest(fn(),_a,_q); } else { idx++; }

    // T14: Many valid labels, random queries
    if (need()) { auto _a=arrManyValid(N2, 100000); auto _q=qRandom(N2, Q2); writeTest(fn(),_a,_q); } else { idx++; }

    // T15: Almost valid labels
    if (need()) { auto _a=arrAlmostValid(N2, 100000); auto _q=qRandom(N2, Q2); writeTest(fn(),_a,_q); } else { idx++; }

    // T16: Blocks + sliding window
    if (need()) { auto _a=arrBlocks(N2); auto _q=qSliding(N2, Q2); writeTest(fn(),_a,_q); } else { idx++; }

    // T17: Boundary valid + suffix queries
    if (need()) { auto _a=arrBoundaryValid(N2); auto _q=qSuffixes(N2, Q2); writeTest(fn(),_a,_q); } else { idx++; }

    // T18: Short queries (length 1-10) — boundary stress
    if (need()) { auto _a=arrRandom(N2, N2); auto _q=qShort(N2, Q2); writeTest(fn(),_a,_q); } else { idx++; }

    // T19: Tiny queries (length 1-2) — most labels impossible
    if (need()) { auto _a=arrManyValid(N2, 100000); auto _q=qTiny(N2, Q2); writeTest(fn(),_a,_q); } else { idx++; }

    // T20: Fully random — general stress
    if (need()) { auto _a=arrRandom(N2, 100000); auto _q=qRandom(N2, Q2); writeTest(fn(),_a,_q); } else { idx++; }

    // ══════════════════════════════════════════════
    //  SUBTASK 3  n,q <= 100000, all l=1
    // ══════════════════════════════════════════════
    cerr << "\n[Subtask 3] n,q <= 100000, l=1\n";
    int N3 = 100000, Q3 = 100000;

    // T21: All same value, prefix queries
    if (need()) { auto _a=arrAllSame(N3, N3); auto _q=qPrefixes(N3, Q3); writeTest(fn(),_a,_q); } else { idx++; }

    // T22: Permutation, prefix queries
    if (need()) { auto _a=arrPermutation(N3); auto _q=qPrefixes(N3, Q3); writeTest(fn(),_a,_q); } else { idx++; }

    // T23: All large → always 0, prefix queries
    if (need()) { auto _a=arrAllLarge(N3, 100000); auto _q=qPrefixes(N3, Q3); writeTest(fn(),_a,_q); } else { idx++; }

    // T24: Many valid labels, prefix queries
    if (need()) { auto _a=arrManyValid(N3, 100000); auto _q=qPrefixes(N3, Q3); writeTest(fn(),_a,_q); } else { idx++; }

    // T25: Almost valid, prefix queries
    if (need()) { auto _a=arrAlmostValid(N3, 100000); auto _q=qPrefixes(N3, Q3); writeTest(fn(),_a,_q); } else { idx++; }

    // T26: Blocks, prefix queries — valid labels cross prefix boundary
    if (need()) { auto _a=arrBlocks(N3); auto _q=qPrefixes(N3, Q3); writeTest(fn(),_a,_q); } else { idx++; }

    // T27: Boundary valid, all prefixes in order [1,1],[1,2],...,[1,n]
    if (need()) {
        auto a = arrBoundaryValid(N3);
            vector<pair<int,int>> qs;
            for (int r = 1; r <= N3 && (int)qs.size() < Q3; r++) qs.push_back({1, r});
            while ((int)qs.size() < Q3) qs.push_back({1, randInt(1,N3)});
            writeTest(fn(), a, qs);
    } else { idx++; }

    // T28: Small values (1..50), prefix queries — many x can accumulate to exact count
    if (need()) { auto _a=arrSmallVals(N3, 50); auto _q=qPrefixes(N3, Q3); writeTest(fn(),_a,_q); } else { idx++; }

    // T29: r=n for all queries (whole array repeated)
    if (need()) { auto _a=arrManyValid(N3, 100000); auto _q=qFull(N3, Q3); writeTest(fn(),_a,_q); } else { idx++; }

    // T30: Random array, prefix queries
    if (need()) { auto _a=arrRandom(N3, 100000); auto _q=qPrefixes(N3, Q3); writeTest(fn(),_a,_q); } else { idx++; }

    // ══════════════════════════════════════════════
    //  SUBTASK 4  n,q <= 100000, a[i] <= 100  (T30..T44)
    // ══════════════════════════════════════════════
    cerr << "\n[Subtask 4] n,q <= 100000, a[i] <= 100\n";
    int N4 = 100000, Q4 = 100000;

    // T30+1: All same value=1
    if (need()) { auto _a=arrAllSame(N4, 1); auto _q=qRandom(N4, Q4); writeTest(fn(),_a,_q); } else { idx++; }

    // T30+2: All same value=100
    if (need()) { auto _a=arrAllSame(N4, 100); auto _q=qRandom(N4, Q4); writeTest(fn(),_a,_q); } else { idx++; }

    // T30+3: Values in {1,2}
    if (need()) {
        vector<int> a(N4);
            for (auto& x : a) x = randInt(1, 2);
            writeTest(fn(), a, qRandom(N4, Q4));
    } else { idx++; }

    // T30+4: Small values 1..10, many repeats
    if (need()) { auto _a=arrSmallVals(N4, 10); auto _q=qRandom(N4, Q4); writeTest(fn(),_a,_q); } else { idx++; }

    // T30+5: Small values 1..100, sliding window
    if (need()) { auto _a=arrSmallVals(N4, 100); auto _q=qSliding(N4, Q4); writeTest(fn(),_a,_q); } else { idx++; }

    // T30+6: Almost valid with small values
    if (need()) { auto _a=arrAlmostValid(N4, 100); auto _q=qRandom(N4, Q4); writeTest(fn(),_a,_q); } else { idx++; }

    // T30+7: Valid labels 1..100 planted fully, rest random small values
    if (need()) {
        vector<int> a;
            for (int x = 1; x <= 100 && (int)a.size() + x <= N4; x++)
                for (int j = 0; j < x; j++) a.push_back(x);
            while ((int)a.size() < N4) a.push_back(randInt(1, 100));
            shuffle(a.begin(), a.end(), rng);
            writeTest(fn(), a, qRandom(N4, Q4));
    } else { idx++; }

    // T30+8: Short queries, small values
    if (need()) { auto _a=arrSmallVals(N4, 100); auto _q=qShort(N4, Q4); writeTest(fn(),_a,_q); } else { idx++; }

    // T30+9: Suffix queries, small values
    if (need()) { auto _a=arrSmallVals(N4, 100); auto _q=qSuffixes(N4, Q4); writeTest(fn(),_a,_q); } else { idx++; }

    // T30+10: Full array queries, small values
    if (need()) { auto _a=arrSmallVals(N4, 100); auto _q=qFull(N4, Q4); writeTest(fn(),_a,_q); } else { idx++; }

    // T30+11: Blocks + random queries, small values
    if (need()) { auto _a=arrBlocks(N4); auto _q=qRandom(N4, Q4); writeTest(fn(),_a,_q); } else { idx++; }

    // T30+12: Boundary valid + suffix queries, small values (≤100)
    if (need()) {
        auto a = arrBoundaryValid(N4);
            // clamp values to <=100 for subtask 4
            for (auto& x : a) x = min(x, 100);
            writeTest(fn(), a, qSuffixes(N4, Q4));
    } else { idx++; }

    // T30+13: Anti-Mo #1 — small values, queries alternate between two distant blocks
    // Mo sorts by block of l then r; alternating l-blocks with random r forces
    // maximal pointer movement in both dimensions.
    if (need()) {
        auto a = arrSmallVals(N4, 100);
            int B = max(1, (int)sqrt(N4));
            vector<pair<int,int>> qs;
            qs.reserve(Q4);
            for (int i = 0; i < Q4; i++) {
                // alternate l between block 0 and block 1
                int block = i & 1;
                int l = randInt(block * B + 1, (block + 1) * B);
                l = min(l, N4);
                int r = randInt(l, N4);
                qs.push_back({l, r});
            }
            writeTest(fn(), a, qs);
    } else { idx++; }

    // T30+14: Anti-Mo #2 — small values, queries zigzag across ALL blocks
    // l cycles through blocks 0,1,2,...,k,k-1,...,0 repeatedly,
    // r is chosen to be far from previous r (alternates near/far).
    if (need()) {
        auto a = arrSmallVals(N4, 100);
            int B = max(1, (int)sqrt(N4));
            int numBlocks = (N4 + B - 1) / B;
            vector<pair<int,int>> qs;
            qs.reserve(Q4);
            for (int i = 0; i < Q4; i++) {
                // ping-pong block index: 0,1,2,...,numBlocks-1,numBlocks-1,...,0
                int period = 2 * numBlocks;
                int pos = i % period;
                int blockIdx = (pos < numBlocks) ? pos : (period - 1 - pos);
                int lLo = blockIdx * B + 1;
                int lHi = min((blockIdx + 1) * B, N4);
                int l = randInt(lLo, lHi);
                // r alternates between near and far half
                int r;
                int mid = N4 / 2;
                if (i & 1) r = randInt(l, max(l, mid));   // [l, max(l,mid)]
                else        r = randInt(mid, N4);
                r = max(r, l);
                qs.push_back({l, r});
            }
            writeTest(fn(), a, qs);
    } else { idx++; }

    // T30+15: Anti-Mo #3 — small values, worst-case Mo block interleaving
    // Queries interleave even-block and odd-block l values — forces Mo to
    // jump between block groups on every step.
    if (need()) {
        auto a = arrSmallVals(N4, 100);
            int B = max(1, (int)sqrt(N4));
            int numBlocks = (N4 + B - 1) / B;
            vector<pair<int,int>> qs;
            qs.reserve(Q4);
            for (int i = 0; i < Q4; i++) {
                // alternate even/odd blocks each query
                int blockIdx = ((randInt(0, numBlocks/2 - 1)) * 2) + (i & 1);
                blockIdx = min(blockIdx, numBlocks - 1);
                int lLo = blockIdx * B + 1, lHi = min((blockIdx+1)*B, N4);
                int l = randInt(lLo, lHi);
                int r = randInt(l, N4);
                qs.push_back({l, r});
            }
            writeTest(fn(), a, qs);
    } else { idx++; }

    // ══════════════════════════════════════════════
    //  SUBTASK 5  n,q <= 100000, no constraints  (T45..T59)
    // ══════════════════════════════════════════════
    cerr << "\n[Subtask 5] n,q <= 100000, no constraints\n";
    int N5 = 100000, Q5 = 100000;

    // T45+1: All same large value
    if (need()) { auto _a=arrAllSame(N5, N5); auto _q=qRandom(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+2: Permutation — x=1 always valid
    if (need()) { auto _a=arrPermutation(N5); auto _q=qRandom(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+3: All large → always 0
    if (need()) { auto _a=arrAllLarge(N5, 100000); auto _q=qRandom(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+4: Many valid labels, random queries
    if (need()) { auto _a=arrManyValid(N5, 100000); auto _q=qRandom(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+5: Almost valid — off-by-one traps for large labels
    if (need()) { auto _a=arrAlmostValid(N5, 100000); auto _q=qRandom(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+6: Block structure + sliding window
    if (need()) { auto _a=arrBlocks(N5); auto _q=qSliding(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+7: Boundary valid + suffix queries
    if (need()) { auto _a=arrBoundaryValid(N5); auto _q=qSuffixes(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+8: Short queries (length 1-10)
    if (need()) { auto _a=arrRandom(N5, 100000); auto _q=qShort(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+9: Mix — half small (1..100), half large
    if (need()) {
        vector<int> a(N5);
            for (int i = 0; i < N5/2; i++) a[i] = randInt(1, 100);
            for (int i = N5/2; i < N5; i++) a[i] = randInt(N5/2, 100000);
            shuffle(a.begin(), a.end(), rng);
            writeTest(fn(), a, qRandom(N5, Q5));
    } else { idx++; }

    // T45+10: Worst case — maximum n,q, fully random
    if (need()) { auto _a=arrRandom(N5, 100000); auto _q=qRandom(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+11: Many valid labels + suffix queries
    if (need()) { auto _a=arrManyValid(N5, 100000); auto _q=qSuffixes(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+12: Permutation + sliding window
    if (need()) { auto _a=arrPermutation(N5); auto _q=qSliding(N5, Q5); writeTest(fn(),_a,_q); } else { idx++; }

    // T45+13: Anti-Mo #1 — random array, queries alternate between two distant blocks
    if (need()) {
        auto a = arrRandom(N5, 100000);
            int B = max(1, (int)sqrt(N5));
            vector<pair<int,int>> qs;
            qs.reserve(Q5);
            for (int i = 0; i < Q5; i++) {
                int block = i & 1;
                int l = randInt(block * B + 1, (block + 1) * B);
                l = min(l, N5);
                int r = randInt(l, N5);
                qs.push_back({l, r});
            }
            writeTest(fn(), a, qs);
    } else { idx++; }

    // T45+14: Anti-Mo #2 — many valid labels, queries zigzag across ALL blocks
    if (need()) {
        auto a = arrManyValid(N5, 100000);
            int B = max(1, (int)sqrt(N5));
            int numBlocks = (N5 + B - 1) / B;
            vector<pair<int,int>> qs;
            qs.reserve(Q5);
            for (int i = 0; i < Q5; i++) {
                int period = 2 * numBlocks;
                int pos = i % period;
                int blockIdx = (pos < numBlocks) ? pos : (period - 1 - pos);
                int lLo = blockIdx * B + 1;
                int lHi = min((blockIdx + 1) * B, N5);
                int l = randInt(lLo, lHi);
                int r;
                int mid5 = N5 / 2;
                if (i & 1) r = randInt(l, max(l, mid5));
                else        r = randInt(mid5, N5);
                r = max(r, l);
                qs.push_back({l, r});
            }
            writeTest(fn(), a, qs);
    } else { idx++; }

    // T45+15: Anti-Mo #3 — random array, even/odd block interleaving
    if (need()) {
        auto a = arrRandom(N5, 100000);
            int B = max(1, (int)sqrt(N5));
            int numBlocks = (N5 + B - 1) / B;
            vector<pair<int,int>> qs;
            qs.reserve(Q5);
            for (int i = 0; i < Q5; i++) {
                int blockIdx = ((randInt(0, numBlocks/2 - 1)) * 2) + (i & 1);
                blockIdx = min(blockIdx, numBlocks - 1);
                int lLo = blockIdx * B + 1, lHi = min((blockIdx+1)*B, N5);
                int l = randInt(lLo, lHi);
                int r = randInt(l, N5);
                qs.push_back({l, r});
            }
            writeTest(fn(), a, qs);
    } else { idx++; }

    cerr << "\nDone! Generated " << idx - 1 << " tests in tests/\n";
    return 0;
}
