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

struct Event {
    int l, r, val;
};

struct Node {
    int left = 0, right = 0;
    int lazy = 0;
};

vector<Node> seg;

int clone_node(int v) {
    seg.push_back(seg[v]);
    return (int)seg.size() - 1;
}

int update(int v, int tl, int tr, int l, int r, int val) {
    if (l > r) return v;

    int nv = clone_node(v);

    if (l == tl && r == tr) {
        seg[nv].lazy += val;
        return nv;
    }

    int tm = (tl + tr) / 2;

    seg[nv].left = update(seg[nv].left, tl, tm, l, min(r, tm), val);
    seg[nv].right = update(seg[nv].right, tm + 1, tr, max(l, tm + 1), r, val);

    return nv;
}

int query(int v, int tl, int tr, int pos) {
    if (tl == tr) return seg[v].lazy;

    int tm = (tl + tr) / 2;

    if (pos <= tm) {
        return seg[v].lazy + query(seg[v].left, tl, tm, pos);
    } else {
        return seg[v].lazy + query(seg[v].right, tm + 1, tr, pos);
    }
}

int build(int tl, int tr) {
    int v = seg.size();
    seg.push_back(Node());

    if (tl == tr) return v;

    int tm = (tl + tr) / 2;
    seg[v].left = build(tl, tm);
    seg[v].right = build(tm + 1, tr);

    return v;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(0);

    int n, q, c;
    cin >> n >> q >> c;

    vector<int> a(n + 1);
    unordered_map<int, vector<int>> pos;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] <= n) {
            pos[a[i]].push_back(i);
        }
    }

    vector<vector<Event>> events(n + 2);

    for (auto &[x, v] : pos) {
        int k = v.size();

        for (int i = 0; i + x - 1 < k; i++) {
            int Lmin = (i == 0 ? 1 : v[i - 1] + 1);
            int Lmax = v[i];

            int Rstart = v[i + x - 1];
            int Rend = (i + x < k ? v[i + x] - 1 : n);

            events[Rstart].push_back({Lmin, Lmax, +1});

            if (Rend + 1 <= n) {
                events[Rend + 1].push_back({Lmin, Lmax, -1});
            }
        }
    }

    seg.reserve(25 * n);
    seg.push_back(Node());

    vector<int> root(n + 1);
    root[0] = build(1, n);

    for (int r = 1; r <= n; r++) {
        root[r] = root[r - 1];

        for (auto e : events[r]) {
            root[r] = update(root[r], 1, n, e.l, e.r, e.val);
        }
    }

    int last = 0;
    while (q--) {
        int l, r;
        cin >> l >> r;
        l ^= c*last;
        r ^= c*last;

        last = query(root[r], 1, n, l);
        cout << last << '\n';
    }

    return 0;
}
