/* 	Problem: COT2 - Count on a Tree II
	Judge: Spoj
	Link: http://www.spoj.com/problems/COT2/
*/

#include <bits/stdc++.h>
#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a, b) for(int a = adj[b]; a != -1; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf(" %s", s)
#define pri(x) printf("%d\n", x)
#define X first
#define Y second
#define mp make_pair
#define pb push_back

using namespace std;
const int inf = 0x3f3f3f3f;
const int minusinf = -inf;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi > vii;
typedef std::pair<int, int> pii;

struct Query{
	int L, R;
	int t;
	int idx;
};

const int mv = 111111;
int K;

ll ans[mv];
int A[mv], L[mv], R[mv], countL[2*mv], countR[2*mv];
int N, Q, M;

bool comp(Query &a, Query &b){
	if(a.L/M != b.L/M) return a.L/M < b.L/M;
	else return a.R < b.R;
}

Query pergs[mv];

int res;
int xL, xR;

void addr(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countL[L[p]^K];
}

void addl(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countR[R[p]^K];
}

void removel(int p){
	res-=countR[R[p]^K];
	countL[L[p]^A[p]]--;
	countR[R[p]^A[p]]--;
}

void remover(int p){
	res-=countL[L[p]^K];
	countR[R[p]^A[p]]--;
	countL[L[p]^A[p]]--;
}

int main(){
	sc2(N, Q);
	sc(K);
	M = sqrt(N);
	if(M*M < N) M++;
	rp(i, N){
		sc(A[i]);
	}
	R[N-1] = A[N-1];
	for(int i = N-2; i>=0; --i){
		R[i] = A[i] ^ R[i+1];
	}
	L[0] = A[0];
	for(int i = 1; i<N; ++i){
		L[i] = L[i-1] ^ A[i];
	}
	/*
	rp(i, N){
		printf("%d: %d\n", i, L[i]);
	}
	puts("");
	rp(i, N){
		printf("%d: %d\n", i, R[i]);
	}
	puts("");
	*/
	int a, b;
	rp(i, Q){
		sc2(a,b);
		a--;
		pergs[i].L = a;
		pergs[i].R = b;
		pergs[i].idx = i;
	}
	sort(pergs, pergs+Q, comp);
	int curL = 0, curR = 0;
	res = 0;
	xL = 0;
	xR = 0;
	rp(i, Q){
		int L = pergs[i].L, R = pergs[i].R, idx = pergs[i].idx;
		while(curL > L){
			addl(--curL);
		}
		while(curR < R){
			addr(curR++);
		}
		while(curL < L){
			removel(curL++);
		}
		while(curR > R){
			remover(--curR);
		}
		ans[idx] = res;
	}
	rp(i, Q){
		printf("%lld\n", ans[i]);
	}
    return 0;
}


/* 	Problem: COT2 - Count on a Tree II
	Judge: Spoj
	Link: http://www.spoj.com/problems/COT2/
*/

#include <bits/stdc++.h>
#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a, b) for(int a = adj[b]; a != -1; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf(" %s", s)
#define pri(x) printf("%d\n", x)
#define X first
#define Y second
#define mp make_pair
#define pb push_back

using namespace std;
const int inf = 0x3f3f3f3f;
const int minusinf = -inf;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi > vii;
typedef std::pair<int, int> pii;

struct Query{
	int L, R;
	int t;
	int idx;
};

const int mv = 111111;
int K;

ll ans[mv];
int A[mv], L[mv], R[mv], countL[22222222], countR[22222222];
int N, Q, M;

bool comp(Query &a, Query &b){
	if(a.L/M != b.L/M) return a.L/M < b.L/M;
	else return a.R < b.R;
}

Query pergs[mv];

int res;
int xL, xR;

void addr(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countL[L[p]^K];
}

void addl(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countR[R[p]^K];
}

void removel(int p){
	res-=countR[R[p]^K];
	countL[L[p]^A[p]]--;
	countR[R[p]^A[p]]--;
}

void remover(int p){
	res-=countL[L[p]^K];
	countR[R[p]^A[p]]--;
	countL[L[p]^A[p]]--;
}

int main(){
	sc2(N, Q);
	sc(K);
	M = sqrt(N);
	if(M*M < N) M++;
	rp(i, N){
		sc(A[i]);
	}
	R[N-1] = A[N-1];
	for(int i = N-2; i>=0; --i){
		R[i] = A[i] ^ R[i+1];
	}
	L[0] = A[0];
	for(int i = 1; i<N; ++i){
		L[i] = L[i-1] ^ A[i];
	}
	/*
	rp(i, N){
		printf("%d: %d\n", i, L[i]);
	}
	puts("");
	rp(i, N){
		printf("%d: %d\n", i, R[i]);
	}
	puts("");
	*/
	int a, b;
	rp(i, Q){
		sc2(a,b);
		a--;
		pergs[i].L = a;
		pergs[i].R = b;
		pergs[i].idx = i;
	}
	sort(pergs, pergs+Q, comp);
	int curL = 0, curR = 0;
	res = 0;
	xL = 0;
	xR = 0;
	rp(i, Q){
		int L = pergs[i].L, R = pergs[i].R, idx = pergs[i].idx;
		while(curL > L){
			addl(--curL);
		}
		while(curR < R){
			addr(curR++);
		}
		while(curL < L){
			removel(curL++);
		}
		while(curR > R){
			remover(--curR);
		}
		ans[idx] = res;
	}
	rp(i, Q){
		printf("%lld\n", ans[i]);
	}
    return 0;
}


/* 	Problem: COT2 - Count on a Tree II
	Judge: Spoj
	Link: http://www.spoj.com/problems/COT2/
*/

#include <bits/stdc++.h>
#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a, b) for(int a = adj[b]; a != -1; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf(" %s", s)
#define pri(x) printf("%d\n", x)
#define X first
#define Y second
#define mp make_pair
#define pb push_back

using namespace std;
const int inf = 0x3f3f3f3f;
const int minusinf = -inf;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi > vii;
typedef std::pair<int, int> pii;

struct Query{
	int L, R;
	int t;
	int idx;
};

const int mv = 111111;
int K;

ll ans[mv];
int A[mv], L[mv], R[mv], countL[mv], countR[mv], V[mv];
int N, Q, M;

bool comp(Query &a, Query &b){
	if(a.L/M != b.L/M) return a.L/M < b.L/M;
	else return a.R < b.R;
}

Query pergs[mv];

int res;
int xL, xR;

void addr(int p){
	res+=countL[L[p]^K];
	countL[L[p]]++;
	countR[R[p]]++;
	xR = R[p+1];
}

void addl(int p){
	res+=countR[R[p]^K];
	countR[R[p]]++;
	countL[L[p]]++;
	if(p>0) xL = L[p-1];
	else xL = 0;
}

void removel(int p){
	res-=countR[R[p]^K];
	countR[R[p]]--;
	countL[L[p]]--;
	xL = L[p];
}

void remover(int p){
	res-=countL[L[p]^K];
	countL[L[p]]--;
	countR[R[p]]--;
	xR = R[p];
}

int main(){
	sc2(N, Q);
	sc(K);
	M = sqrt(N);
	if(M*M < N) M++;
	rp(i, N){
		sc(A[i]);
	}
	R[N-1] = A[N-1];
	for(int i = N-2; i>=0; --i){
		R[i] = A[i] ^ R[i+1];
	}
	L[0] = A[0];
	for(int i = 1; i<N; ++i){
		L[i] = L[i-1] ^ A[i];
	}
	/*
	rp(i, N){
		printf("%d: %d\n", i, L[i]);
	}
	puts("");
	rp(i, N){
		printf("%d: %d\n", i, R[i]);
	}
	puts("");
	*/
	int a, b;
	rp(i, Q){
		sc2(a,b);
		a--;
		pergs[i].L = a;
		pergs[i].R = b;
		pergs[i].idx = i;
	}
	sort(pergs, pergs+Q, comp);
	int curL = 0, curR = 0;
	res = 0;
	xL = 0;
	xR = 0;
	L[N] = R[N] = 0;
	rp(i, Q){
		int L = pergs[i].L, R = pergs[i].R, idx = pergs[i].idx;
		countR[xR]++;
		while(curL > L){
			addl(--curL);
	//		printf("a: %d %d\n", curL, res);
		}
		countR[xR]--;
		countL[xL]++;
		while(curR < R){
			addr(curR++);
	//		printf("a: %d %d\n", curR-1, res);
		}
		countL[xL]--;
		countR[xR]++;
		while(curL < L){
			removel(curL++);
	//		printf("r: %d %d\n", curL-1, res);
		}
		countR[xR]--;
		countL[xL]++;
		while(curR > R){
			remover(--curR);
	//		printf("r: %d %d\n", curR, res);
		}
		countL[xL]--;
		ans[idx] = res;
	}
//	puts("");
	rp(i, Q){
		printf("%I64d\n", ans[i]);
	}
    return 0;
}


/* 	Problem: COT2 - Count on a Tree II
	Judge: Spoj
	Link: http://www.spoj.com/problems/COT2/
*/

#include <bits/stdc++.h>
#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a, b) for(int a = adj[b]; a != -1; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf(" %s", s)
#define pri(x) printf("%d\n", x)
#define X first
#define Y second
#define mp make_pair
#define pb push_back

using namespace std;
const int inf = 0x3f3f3f3f;
const int minusinf = -inf;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi > vii;
typedef std::pair<int, int> pii;

struct Query{
	int L, R;
	int t;
	int idx;
};

const int mv = 111111;
int K;

ll ans[mv];
int A[mv], L[mv], R[mv], countL[2222222], countR[2222222];
int N, Q, M;

bool comp(Query &a, Query &b){
	if(a.L/M != b.L/M) return a.L/M < b.L/M;
	else return a.R < b.R;
}

Query pergs[mv];

int res;
int xL, xR;

void addr(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countL[L[p]^K];
}

void addl(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countR[R[p]^K];
}

void removel(int p){
	res-=countR[R[p]^K];
	countL[L[p]^A[p]]--;
	countR[R[p]^A[p]]--;
}

void remover(int p){
	res-=countL[L[p]^K];
	countR[R[p]^A[p]]--;
	countL[L[p]^A[p]]--;
}

int main(){
	sc2(N, Q);
	sc(K);
	M = sqrt(N);
	if(M*M < N) M++;
	rp(i, N){
		sc(A[i]);
	}
	R[N-1] = A[N-1];
	for(int i = N-2; i>=0; --i){
		R[i] = A[i] ^ R[i+1];
	}
	L[0] = A[0];
	for(int i = 1; i<N; ++i){
		L[i] = L[i-1] ^ A[i];
	}
	/*
	rp(i, N){
		printf("%d: %d\n", i, L[i]);
	}
	puts("");
	rp(i, N){
		printf("%d: %d\n", i, R[i]);
	}
	puts("");
	*/
	int a, b;
	rp(i, Q){
		sc2(a,b);
		a--;
		pergs[i].L = a;
		pergs[i].R = b;
		pergs[i].idx = i;
	}
	sort(pergs, pergs+Q, comp);
	int curL = 0, curR = 0;
	res = 0;
	xL = 0;
	xR = 0;
	rp(i, Q){
		int L = pergs[i].L, R = pergs[i].R, idx = pergs[i].idx;
		while(curL > L){
			addl(--curL);
		}
		while(curR < R){
			addr(curR++);
		}
		while(curL < L){
			removel(curL++);
		}
		while(curR > R){
			remover(--curR);
		}
		ans[idx] = res;
	}
	rp(i, Q){
		printf("%I64d\n", ans[i]);
	}
    return 0;
}


/* 	Problem: COT2 - Count on a Tree II
	Judge: Spoj
	Link: http://www.spoj.com/problems/COT2/
*/

#include <bits/stdc++.h>
#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a, b) for(int a = adj[b]; a != -1; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf(" %s", s)
#define pri(x) printf("%d\n", x)
#define X first
#define Y second
#define mp make_pair
#define pb push_back

using namespace std;
const int inf = 0x3f3f3f3f;
const int minusinf = -inf;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi > vii;
typedef std::pair<int, int> pii;

struct Query{
	int L, R;
	int t;
	int idx;
};

const int mv = 111111;
const int mt = 5555555;
int K;

ll ans[mv];
int A[mv], L[mv], R[mv];
ll countL[mt], countR[mt];
int N, Q, M;

bool comp(Query &a, Query &b){
	if(a.L/M != b.L/M) return a.L/M < b.L/M;
	else return a.R < b.R;
}

Query pergs[mv];

int res;
int xL, xR;

void addr(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countL[L[p]^K];
}

void addl(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countR[R[p]^K];
}

void removel(int p){
	res-=countR[R[p]^K];
	countL[L[p]^A[p]]--;
	countR[R[p]^A[p]]--;
}

void remover(int p){
	res-=countL[L[p]^K];
	countR[R[p]^A[p]]--;
	countL[L[p]^A[p]]--;
}

int main(){
	sc2(N, Q);
	sc(K);
	M = sqrt(N);
	if(M*M < N) M++;
	rp(i, N){
		sc(A[i]);
	}
	R[N-1] = A[N-1];
	for(int i = N-2; i>=0; --i){
		R[i] = A[i] ^ R[i+1];
	}
	L[0] = A[0];
	for(int i = 1; i<N; ++i){
		L[i] = L[i-1] ^ A[i];
	}
	/*
	rp(i, N){
		printf("%d: %d\n", i, L[i]);
	}
	puts("");
	rp(i, N){
		printf("%d: %d\n", i, R[i]);
	}
	puts("");
	*/
	int a, b;
	rp(i, Q){
		sc2(a,b);
		a--;
		pergs[i].L = a;
		pergs[i].R = b;
		pergs[i].idx = i;
	}
	sort(pergs, pergs+Q, comp);
	int curL = 0, curR = 0;
	res = 0;
	xL = 0;
	xR = 0;
	rp(i, Q){
		int L = pergs[i].L, R = pergs[i].R, idx = pergs[i].idx;
		while(curL > L){
			addl(--curL);
		}
		while(curR < R){
			addr(curR++);
		}
		while(curL < L){
			removel(curL++);
		}
		while(curR > R){
			remover(--curR);
		}
		ans[idx] = res;
	}
	rp(i, Q){
		printf("%lld\n", ans[i]);
	}
    return 0;
}


/* 	Problem: COT2 - Count on a Tree II
	Judge: Spoj
	Link: http://www.spoj.com/problems/COT2/
*/

#include <bits/stdc++.h>
#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a, b) for(int a = adj[b]; a != -1; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf(" %s", s)
#define pri(x) printf("%d\n", x)
#define X first
#define Y second
#define mp make_pair
#define pb push_back

using namespace std;
const int inf = 0x3f3f3f3f;
const int minusinf = -inf;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi > vii;
typedef std::pair<int, int> pii;

struct Query{
	int L, R;
	int t;
	int idx;
};

const int mv = 111111;
int K;

ll ans[mv];
int A[mv], L[mv], R[mv], countL[mv], countR[mv], V[mv];
int N, Q, M;

bool comp(Query &a, Query &b){
	if(a.L/M != b.L/M) return a.L/M < b.L/M;
	else return a.R < b.R;
}

Query pergs[mv];

int res;
int xL, xR;

void addr(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countL[L[p]^K];
}

void addl(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countR[R[p]^K];
}

void removel(int p){
	res-=countR[R[p]^K];
	countL[L[p]^A[p]]--;
	countR[R[p]^A[p]]--;
}

void remover(int p){
	res-=countL[L[p]^K];
	countR[R[p]^A[p]]--;
	countL[L[p]^A[p]]--;
}

int main(){
	sc2(N, Q);
	sc(K);
	M = sqrt(N);
	if(M*M < N) M++;
	rp(i, N){
		sc(A[i]);
	}
	R[N-1] = A[N-1];
	for(int i = N-2; i>=0; --i){
		R[i] = A[i] ^ R[i+1];
	}
	L[0] = A[0];
	for(int i = 1; i<N; ++i){
		L[i] = L[i-1] ^ A[i];
	}
	/*
	rp(i, N){
		printf("%d: %d\n", i, L[i]);
	}
	puts("");
	rp(i, N){
		printf("%d: %d\n", i, R[i]);
	}
	puts("");
	*/
	int a, b;
	rp(i, Q){
		sc2(a,b);
		a--;
		pergs[i].L = a;
		pergs[i].R = b;
		pergs[i].idx = i;
	}
	sort(pergs, pergs+Q, comp);
	int curL = 0, curR = 0;
	res = 0;
	xL = 0;
	xR = 0;
	rp(i, Q){
		int L = pergs[i].L, R = pergs[i].R, idx = pergs[i].idx;
		while(curL > L){
			addl(--curL);
		}
		while(curR < R){
			addr(curR++);
		}
		while(curL < L){
			removel(curL++);
		}
		while(curR > R){
			remover(--curR);
		}
		ans[idx] = res;
	}
	rp(i, Q){
		printf("%lld\n", ans[i]);
	}
    return 0;
}


/* 	Problem: COT2 - Count on a Tree II
	Judge: Spoj
	Link: http://www.spoj.com/problems/COT2/
*/

#include <bits/stdc++.h>
#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a, b) for(int a = adj[b]; a != -1; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf(" %s", s)
#define pri(x) printf("%d\n", x)
#define X first
#define Y second
#define mp make_pair
#define pb push_back

using namespace std;
const int inf = 0x3f3f3f3f;
const int minusinf = -inf;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi > vii;
typedef std::pair<int, int> pii;

struct Query{
	int L, R;
	int t;
	int idx;
};

const int mv = 111111;
int K;

ll ans[mv];
int A[mv], L[mv], R[mv];
ll countL[22222222], countR[22222222];
int N, Q, M;

bool comp(Query &a, Query &b){
	if(a.L/M != b.L/M) return a.L/M < b.L/M;
	else return a.R < b.R;
}

Query pergs[mv];

int res;
int xL, xR;

void addr(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countL[L[p]^K];
}

void addl(int p){
	countL[L[p]^A[p]]++;
	countR[R[p]^A[p]]++;
	res+=countR[R[p]^K];
}

void removel(int p){
	res-=countR[R[p]^K];
	countL[L[p]^A[p]]--;
	countR[R[p]^A[p]]--;
}

void remover(int p){
	res-=countL[L[p]^K];
	countR[R[p]^A[p]]--;
	countL[L[p]^A[p]]--;
}

int main(){
	sc2(N, Q);
	sc(K);
	M = sqrt(N);
	if(M*M < N) M++;
	rp(i, N){
		sc(A[i]);
	}
	R[N-1] = A[N-1];
	for(int i = N-2; i>=0; --i){
		R[i] = A[i] ^ R[i+1];
	}
	L[0] = A[0];
	for(int i = 1; i<N; ++i){
		L[i] = L[i-1] ^ A[i];
	}
	/*
	rp(i, N){
		printf("%d: %d\n", i, L[i]);
	}
	puts("");
	rp(i, N){
		printf("%d: %d\n", i, R[i]);
	}
	puts("");
	*/
	int a, b;
	rp(i, Q){
		sc2(a,b);
		a--;
		pergs[i].L = a;
		pergs[i].R = b;
		pergs[i].idx = i;
	}
	sort(pergs, pergs+Q, comp);
	int curL = 0, curR = 0;
	res = 0;
	xL = 0;
	xR = 0;
	rp(i, Q){
		int L = pergs[i].L, R = pergs[i].R, idx = pergs[i].idx;
		while(curL > L){
			addl(--curL);
		}
		while(curR < R){
			addr(curR++);
		}
		while(curL < L){
			removel(curL++);
		}
		while(curR > R){
			remover(--curR);
		}
		ans[idx] = res;
	}
	rp(i, Q){
		printf("%lld\n", ans[i]);
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], pref[N], cnts[(int)1e6 + 10], cntp[(int)1e6 + 10], len, id[N];
long long res[N], b[320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    //n = 10, q = 1e3, k = uniform_int_distribution<int>(1, 10)(rng);
    int curr = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        //arr[i] = uniform_int_distribution<int>(1, 10)(rng);
        curr^=arr[i];
        pref[i] = curr;
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = curr;
        curr^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[suf[i]]++;
        for(int i=l;i<r;i++){
            cnts[suf[i]]--;
            b[c][c]+=cnts[(k ^ suf[i])];
            b[c][c]+=((suf[i] ^ suf[r]) == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c], curp = 0;
        int l = 1 + (c - 1) * len, r = 1 + c * len;
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            curp^=arr[i];
            cur+=cnts[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            if(j==len || i==n){
                b[c][id[i]] = cur;
                j = 0;
            }
            cntp[curp]++;
        }
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        //Q[i].l = uniform_int_distribution<int>(1, n)(rng);
        //Q[i].r = uniform_int_distribution<int>(Q[i].l, n)(rng);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnts[suf[1]] = 1;
    cntp[pref[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnts[suf[L]]++;
            cntp[pref[L]]++;
        }
        while(L < Q[i].l){
            cnts[suf[L]]--;
            cntp[pref[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnts[suf[R]]++;
            cntp[pref[R]]++;
        }
        while(R > Q[i].r){
            cnts[suf[R]]--;
            cntp[pref[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnts[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnts[suf[j]]--;
                    cur+=cnts[(suf[j] ^ k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(j=R;id[j]==id[R];j--) cnts[suf[j]]++;
            }
            else{
                int lb = id[j], rb = id[j];
                while(min(n, j + len - 1) <= R && rb!=id[n]){
                    rb = id[j];
                    j+=len;
                }
                cur+=b[lb][rb];
                for(j=L;j%len!=1;j++) cntp[pref[j]]--;
                int J = rb*len;
                for(j=R;j>=1+J;j--){
                    cntp[pref[j]]--;
                    cur+=cntp[(k ^ pref[j])];
                    if(L%len==1) cur+=(pref[j] == k);
                }
                for(j=L;j%len!=1;j++) cntp[pref[j]]++;
                for(j=1+J;j<=R;j++) cntp[pref[j]]++;
            }
            for(j=L;j%len!=1;j++) cnts[suf[j]]++;
        }
//        int d = 0;
//        for(int p=L;p<=R;p++){
//            for(int pp=p;pp<=R;pp++) d+=(pref[pp] ^ pref[p - 1]) == k;
//        }
//        if(d!=cur){
//            cout<<k<<'\n';
//            for(int p=1;p<=n;p++) cout<<arr[p]<<' ';
//            puts("");
//            cout<<L<<' '<<R<<'\n';
//            cout<<d<<'\n'<<cur<<'\n';
//            return -1;
//        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], pref[N], cnts[(int)1e6 + 10], cntp[(int)1e6 + 10], len, id[N];
long long res[N], b[320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    //n = 10, q = 1e3, k = uniform_int_distribution<int>(1, 10)(rng);
    int curr = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        //arr[i] = uniform_int_distribution<int>(1, 10)(rng);
        curr^=arr[i];
        pref[i] = curr;
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = curr;
        curr^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[suf[i]]++;
        for(int i=l;i<r;i++){
            cnts[suf[i]]--;
            b[c][c]+=cnts[(k ^ suf[i])];
            b[c][c]+=((suf[i] ^ suf[r]) == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c], curp = 0;
        int l = 1 + (c - 1) * len, r = 1 + c * len;
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            curp^=arr[i];
            cur+=cnts[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            if(j==len || i==n){
                b[c][id[i]] = cur;
                j = 0;
            }
            cntp[curp]++;
        }
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        //Q[i].l = uniform_int_distribution<int>(1, n)(rng);
        //Q[i].r = uniform_int_distribution<int>(Q[i].l, n)(rng);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnts[suf[1]] = 1;
    cntp[pref[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnts[suf[L]]++;
            cntp[pref[L]]++;
        }
        while(L < Q[i].l){
            cnts[suf[L]]--;
            cntp[pref[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnts[suf[R]]++;
            cntp[pref[R]]++;
        }
        while(R > Q[i].r){
            cnts[suf[R]]--;
            cntp[pref[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnts[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnts[suf[j]]--;
                    cur+=cnts[(suf[j] ^ k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(j=R;id[j]==id[R];j--) cnts[suf[j]]++;
            }
            else{
                int lb = id[j], rb = id[j];
                while(min(n, j + len - 1) <= R && rb!=id[n]){
                    rb = id[j];
                    j+=len;
                }
                cur+=b[lb][rb];
                for(j=L;j%len!=1;j++) cntp[pref[j]]--;
                int J = rb*len;
                for(j=R;j>=1+J;j--){
                    cntp[pref[j]]--;
                    cur+=cntp[(k ^ pref[j])];
                    if(L%len==1) cur+=((pref[j] ^ pref[L - 1]) == k);
                }
                for(j=L;j%len!=1;j++) cntp[pref[j]]++;
                for(j=1+J;j<=R;j++) cntp[pref[j]]++;
            }
            for(j=L;j%len!=1;j++) cnts[suf[j]]++;
        }
//        int d = 0;
//        for(int p=L;p<=R;p++){
//            for(int pp=p;pp<=R;pp++) d+=(pref[pp] ^ pref[p - 1]) == k;
//        }
//        if(d!=cur){
//            cout<<k<<'\n';
//            for(int p=1;p<=n;p++) cout<<arr[p]<<' ';
//            puts("");
//            cout<<L<<' '<<R<<'\n';
//            cout<<d<<'\n'<<cur<<'\n';
//            return -1;
//        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], pref[N], cnts[(int)1e6 + 10], cntp[(int)1e6 + 10], len, id[N];
long long res[N], b[320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    int cur = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        cur^=arr[i];
        pref[i] = cur;
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = cur;
        cur^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=l;i<r;i++){
            cnts[(suf[i] ^ suf[r])]--;
            b[c][c]+=cnts[(k^(suf[i] ^ suf[r]))];
            b[c][c]+=((suf[i] ^ suf[r]) == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c], curp = 0;
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            if(j > len) j = 1;
            curp^=arr[i];
            cur+=cnts[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            if(j==len || i==n){
                b[c][id[i]] = cur;
            }
            cntp[curp]++;
        }
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnts[suf[1]] = 1;
    cntp[pref[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnts[suf[L]]++;
            cntp[pref[L]]++;
        }
        while(L < Q[i].l){
            cnts[suf[L]]--;
            cntp[pref[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnts[suf[R]]++;
            cntp[pref[R]]++;
        }
        while(R > Q[i].r){
            cnts[suf[R]]--;
            cntp[pref[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnts[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnts[suf[j]]--;
                    cur+=cnts[(suf[j] ^ k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(j=R;id[j]==id[R];j--) cnts[suf[j]]++;
            }
            else{
                int lb = id[j], rb = id[j];
                while(min(n, j + len - 1) <= R && rb!=id[n]){
                    rb = id[j];
                    j+=len;
                }
                cur+=b[lb][rb];
                for(j=L;j%len!=1;j++) cntp[pref[j]]--;
                int J = rb*len;
                for(j=R;j>=1+J;j--){
                    cntp[pref[j]]--;
                    cur+=cntp[(k ^ pref[j])];
                    cur+=((pref[j] ^ pref[L - 1]) == k);
                }
                for(j=L;j%len!=1;j++) cntp[pref[j]]++;
                for(j=1+J;j<=R;j++) cntp[pref[j]]++;
            }
            for(j=L;j%len!=1;j++) cnts[suf[j]]++;
        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], pref[N], cnts[(int)1e6 + 10], cntp[(int)1e6 + 10], len, id[N];
long long res[N], b[320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    int cur = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        cur^=arr[i];
        pref[i] = cur;
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = cur;
        cur^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=l;i<r;i++){
            cnts[(suf[i] ^ suf[r])]--;
            b[c][c]+=cnts[(k^(suf[i] ^ suf[r]))];
            b[c][c]+=((suf[i] ^ suf[r]) == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c], curp = 0;
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            if(j > len) j = 1;
            curp^=arr[i];
            cur+=cnts[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            if(j==len || i==n){
                b[c][id[i]] = cur;
            }
            cntp[curp]++;
        }
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnts[suf[1]] = 1;
    cntp[pref[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnts[suf[L]]++;
            cntp[pref[L]]++;
        }
        while(L < Q[i].l){
            cnts[suf[L]]--;
            cntp[pref[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnts[suf[R]]++;
            cntp[pref[R]]++;
        }
        while(R > Q[i].r){
            cnts[suf[R]]--;
            cntp[pref[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnts[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnts[suf[j]]--;
                    cur+=cnts[(suf[j] ^ k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(;id[j]==id[R];j--) cnts[suf[j]]++;
            }
            else{
                int lb = id[j], rb = id[j];
                while(min(n, j + len - 1) <= R && rb!=id[n]){
                    rb = id[j];
                    j+=len;
                }
                cur+=b[lb][rb];
                for(j=L;j%len!=1;j++) cntp[pref[j]]--;
                int J = rb*len;
                for(j=R;j>=1+J;j--){
                    cntp[pref[j]]--;
                    cur+=cntp[(k ^ pref[j])];
                    cur+=((pref[j] ^ pref[L - 1]) == k);
                }
                for(j=L;j%len!=1;j++) cntp[pref[j]]++;
                for(j=1+J;j<=R;j++) cntp[pref[j]]++;
            }
            for(j=L;j%len!=1;j++) cnts[suf[j]]++;
        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], pref[N], cnts[(int)1e6 + 10], cntp[(int)1e6 + 10], len, id[N];
long long res[N], b[320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    int cur = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        cur^=arr[i];
        pref[i] = cur;
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = cur;
        cur^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=l;i<r;i++){
            cnts[(suf[i] ^ suf[r])]--;
            b[c][c]+=cnts[(k^(suf[i] ^ suf[r]))];
            b[c][c]+=((suf[i] ^ suf[r]) == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c], curp = 0;
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            if(j > len) j = 1;
            curp^=arr[i];
            cur+=cnts[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            if(j==len || i==n){
                b[c][id[i]] = cur;
            }
            cntp[curp]++;
        }
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnts[suf[1]] = 1;
    cntp[pref[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnts[suf[L]]++;
            cntp[pref[L]]++;
        }
        while(L < Q[i].l){
            cnts[suf[L]]--;
            cntp[pref[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnts[suf[R]]++;
            cntp[pref[R]]++;
        }
        while(R > Q[i].r){
            cnts[suf[R]]--;
            cntp[pref[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnts[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnts[suf[j]]--;
                    cur+=cnts[(suf[j] ^ k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(;id[j]==id[R];j--) cnts[suf[j]]++;
            }
            else{
                int lb = id[j], rb = id[j];
                while(min(n, j + len - 1) <= R && rb!=id[n]){
                    rb = id[j];
                    j+=len;
                }
                cur+=b[lb][rb];
                for(j=L;j%len!=1;j++) cntp[pref[j]]--;
                int J = rb*len;
                for(j=1+J;j<=R;j++){
                    cntp[pref[j]]--;
                    cur+=cntp[(k ^ pref[j])];
                    if(L==1) cur+=(pref[j] == k);
                }
                for(j=L;j%len!=1;j++) cntp[pref[j]]++;
                for(j=1+J;j<=R;j++) cntp[pref[j]]++;
            }
            for(j=L;j%len!=1;j++) cnts[suf[j]]++;
        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], pref[N], cnts[(1<<22)], cntp[(1<<22)], len, id[N];
long long res[N], b[320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    int curr = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        curr^=arr[i];
        pref[i] = curr;
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = curr;
        curr^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[suf[i]]++;
        for(int i=l;i<r;i++){
            cnts[suf[i]]--;
            b[c][c]+=cnts[(k ^ suf[i])];
            b[c][c]+=((suf[i] ^ suf[r]) == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c], curp = 0;
        int l = 1 + (c - 1) * len, r = 1 + c * len;
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            curp^=arr[i];
            cur+=cnts[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            if(j==len || i==n){
                b[c][id[i]] = cur;
                j = 0;
            }
            cntp[curp]++;
        }
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnts[suf[1]] = 1;
    cntp[pref[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnts[suf[L]]++;
            cntp[pref[L]]++;
        }
        while(L < Q[i].l){
            cnts[suf[L]]--;
            cntp[pref[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnts[suf[R]]++;
            cntp[pref[R]]++;
        }
        while(R > Q[i].r){
            cnts[suf[R]]--;
            cntp[pref[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnts[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnts[suf[j]]--;
                    cur+=cnts[(suf[j] ^ k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(j=R;id[j]==id[R];j--) cnts[suf[j]]++;
            }
            else{
                int lb = id[j], rb = id[j];
                while(min(n, j + len - 1) <= R && rb!=id[n]){
                    rb = id[j];
                    j+=len;
                }
                cur+=b[lb][rb];
                for(j=L;j%len!=1;j++) cntp[pref[j]]--;
                if(L%len!=1) cntp[pref[j-1]]++;
                int J = rb*len;
                for(j=R;j>=1+J;j--){
                    cntp[pref[j]]--;
                    cur+=cntp[(k ^ pref[j])];
                    if(L%len==1) cur+=((pref[j] ^ pref[L - 1]) == k);
                }
                for(j=L;j%len!=1;j++) cntp[pref[j]]++;
                if(L%len!=1) cntp[pref[j-1]]--;
                for(j=1+J;j<=R;j++) cntp[pref[j]]++;
            }
            for(j=L;j%len!=1;j++) cnts[suf[j]]++;
        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], pref[N], cnts[(int)1e6 + 10], cntp[(int)1e6 + 10], len, id[N];
long long res[N], b[320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    int cur = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        cur^=arr[i];
        pref[i] = cur;
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = cur;
        cur^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[suf[i]]++;
        for(int i=l;i<r;i++){
            cnts[suf[i]]--;
            b[c][c]+=cnts[(k ^ suf[i])];
            b[c][c]+=((suf[i] ^ suf[r]) == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c], curp = 0;
        int l = 1 + (c - 1) * len, r = 1 + c * len;
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            curp^=arr[i];
            cur+=cnts[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            if(j==len || i==n){
                b[c][id[i]] = cur;
                j = 1;
            }
            cntp[curp]++;
        }
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnts[suf[1]] = 1;
    cntp[pref[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnts[suf[L]]++;
            cntp[pref[L]]++;
        }
        while(L < Q[i].l){
            cnts[suf[L]]--;
            cntp[pref[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnts[suf[R]]++;
            cntp[pref[R]]++;
        }
        while(R > Q[i].r){
            cnts[suf[R]]--;
            cntp[pref[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnts[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnts[suf[j]]--;
                    cur+=cnts[(suf[j] ^ k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(j=R;id[j]==id[R];j--) cnts[suf[j]]++;
            }
            else{
                int lb = id[j], rb = id[j];
                while(min(n, j + len - 1) <= R && rb!=id[n]){
                    rb = id[j];
                    j+=len;
                }
                cur+=b[lb][rb];
                for(j=L;j%len!=1;j++) cntp[pref[j]]--;
                int J = rb*len;
                for(j=R;j>=1+J;j--){
                    cntp[pref[j]]--;
                    cur+=cntp[(k ^ pref[j])];
                    cur+=((pref[j] ^ pref[L - 1]) == k);
                }
                for(j=L;j%len!=1;j++) cntp[pref[j]]++;
                for(j=1+J;j<=R;j++) cntp[pref[j]]++;
            }
            for(j=L;j%len!=1;j++) cnts[suf[j]]++;
        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], cnt[(int)1e6 + 10], cntp[(int)1e6 + 10], len, id[N], b_pref[320][320], b_suf[320][320];
long long res[N], b[320][320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    int cur = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        cur^=arr[i];
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = cur;
        cur^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len;
        int i = l;
        for(;id[i]==c;i++) b_pref[c][i - l + 1] = (arr[i] ^ b_pref[c][i - l]);
        for(i=i-1;id[i]==c;i--){
            b_suf[c][i - l + 1] = (arr[i] ^ b_suf[c][i - l + 2]);
            cnt[b_suf[c][i - l + 1]]++;
        }
        for(i=i+1;id[i]==c;i++){
            cnt[b_suf[c][i - l + 1]]--;
            b[c][c][len]+=cnt[(k^b_suf[c][i - l + 1])];
            b[c][c][len]+=(b_suf[c][i - l + 1] == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c][len], curp = 0;
        for(int i=1;i<=len;i++) cnt[b_suf[c][i]]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            if(j > len) j = 1;
            curp^=arr[i];
            cur+=cnt[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            b[c][id[i]][j] = cur;
            cntp[curp]++;
        }
        for(int i=1;i<=len;i++) cnt[b_suf[c][i]]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnt[suf[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnt[suf[L]]++;
        }
        while(L < Q[i].l){
            cnt[suf[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnt[suf[R]]++;
        }
        while(R > Q[i].r){
            cnt[suf[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnt[suf[j]]--;
                cur+=cnt[(suf[j]^k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnt[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnt[suf[j]]--;
                cur+=cnt[(suf[j]^k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnt[suf[j]]--;
                    cur+=cnt[(suf[j]^k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(;id[j]==id[R];j--) cnt[suf[j]]++;
            }
            else cur+=b[id[j]][id[R]][(R%len == 0 ? len : R%len)];
            for(j=L;j%len!=1;j++) cnt[suf[j]]++;
        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], pref[N], cnts[(int)1e6 + 10], cntp[(int)1e6 + 10], len, id[N];
long long res[N], b[320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    int curr = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        curr^=arr[i];
        pref[i] = curr;
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = curr;
        curr^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[suf[i]]++;
        for(int i=l;i<r;i++){
            cnts[suf[i]]--;
            b[c][c]+=cnts[(k ^ suf[i])];
            b[c][c]+=((suf[i] ^ suf[r]) == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c], curp = 0;
        int l = 1 + (c - 1) * len, r = 1 + c * len;
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            curp^=arr[i];
            cur+=cnts[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            if(j==len || i==n){
                b[c][id[i]] = cur;
                j = 0;
            }
            cntp[curp]++;
        }
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnts[suf[1]] = 1;
    cntp[pref[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnts[suf[L]]++;
            cntp[pref[L]]++;
        }
        while(L < Q[i].l){
            cnts[suf[L]]--;
            cntp[pref[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnts[suf[R]]++;
            cntp[pref[R]]++;
        }
        while(R > Q[i].r){
            cnts[suf[R]]--;
            cntp[pref[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnts[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnts[suf[j]]--;
                    cur+=cnts[(suf[j] ^ k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(j=R;id[j]==id[R];j--) cnts[suf[j]]++;
            }
            else{
                int lb = id[j], rb = id[j];
                while(min(n, j + len - 1) <= R && rb!=id[n]){
                    rb = id[j];
                    j+=len;
                }
                cur+=b[lb][rb];
                for(j=L;j%len!=1;j++) cntp[pref[j]]--;
                if(L%len!=1) cntp[pref[j-1]]++;
                int J = rb*len;
                for(j=R;j>=1+J;j--){
                    cntp[pref[j]]--;
                    cur+=cntp[(k ^ pref[j])];
                    if(L%len==1) cur+=((pref[j] ^ pref[L - 1]) == k);
                }
                for(j=L;j%len!=1;j++) cntp[pref[j]]++;
                if(L%len!=1) cntp[pref[j-1]]--;
                for(j=1+J;j<=R;j++) cntp[pref[j]]++;
            }
            for(j=L;j%len!=1;j++) cnts[suf[j]]++;
        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], pref[N], cnts[(int)1e6 + 10], cntp[(int)1e6 + 10], len, id[N];
long long res[N], b[320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    int cur = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        cur^=arr[i];
        pref[i] = cur;
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = cur;
        cur^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=l;i<r;i++){
            cnts[(suf[i] ^ suf[r])]--;
            b[c][c]+=cnts[(k^(suf[i] ^ suf[r]))];
            b[c][c]+=((suf[i] ^ suf[r]) == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c], curp = 0;
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            if(j > len) j = 1;
            curp^=arr[i];
            cur+=cnts[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            if(j==len || i==n){
                b[c][id[i]] = cur;
            }
            cntp[curp]++;
        }
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnts[suf[1]] = 1;
    cntp[pref[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnts[suf[L]]++;
            cntp[pref[L]]++;
        }
        while(L < Q[i].l){
            cnts[suf[L]]--;
            cntp[pref[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnts[suf[R]]++;
            cntp[pref[R]]++;
        }
        while(R > Q[i].r){
            cnts[suf[R]]--;
            cntp[pref[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnts[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j] ^ k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnts[suf[j]]--;
                    cur+=cnts[(suf[j] ^ k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(;id[j]==id[R];j--) cnts[suf[j]]++;
            }
            else{
                int lb = id[j], rb = id[j];
                while(min(n, j + len - 1) <= R && rb!=id[n]){
                    rb = id[j];
                    j+=len;
                }
                cur+=b[lb][rb];
                for(j=L;j%len!=1;j++) cntp[pref[j]]--;
                int J = rb*len;
                for(j=1+J;j<=R;j++){
                    cntp[pref[j]]--;
                    cur+=cntp[(k ^ pref[j])];
                }
                for(j=L;j%len!=1;j++) cntp[pref[j]]++;
                for(j=1+J;j<=R;j++) cntp[pref[j]]++;
            }
            for(j=L;j%len!=1;j++) cnts[suf[j]]++;
        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+10, mod=(int)1e9 + 7;
int n, q, k, arr[N], suf[N], pref[N], cnts[(int)1e6 + 10], cntp[(int)1e6 + 10], len, id[N];
long long res[N], b[320][320];
struct Query{
    int l, r, i;
};
bool cmp(const Query &x, const Query &y){
    if(x.l / len != y.l / len) return x.l < y.l;
    if((x.l / len) % 2 == 0) return x.r < y.r;
    return x.r > y.r;
}

int main(){
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%d%d%d", &n, &q, &k);
    int cur = 0;
    len = sqrt(n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        cur^=arr[i];
        pref[i] = cur;
        id[i] = (i / len) + (i%len!=0);
    }
    for(int i=1;i<=n;i++){
        suf[i] = cur;
        cur^=arr[i];
    }
    for(int c=1;c<=id[n];c++){
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=l;i<r;i++){
            cnts[(suf[i] ^ suf[r])]--;
            b[c][c]+=cnts[(k^(suf[i] ^ suf[r]))];
            b[c][c]+=((suf[i] ^ suf[r]) == k);
        }
    }
    for(int c=1;c<id[n];c++){
        long long cur = b[c][c], curp = 0;
        int l = 1 + (c - 1) * len, r = min(n + 1, 1 + c * len);
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]++;
        for(int i=1+c*len, j=1;i<=n;i++, j++){
            if(j > len) j = 1;
            curp^=arr[i];
            cur+=cnts[(curp ^ k)];
            cur+=cntp[(curp ^ k)];
            cur+=(curp == k);
            if(j==len || i==n){
                b[c][id[i]] = cur;
            }
            cntp[curp]++;
        }
        for(int i=l;i<r;i++) cnts[(suf[i] ^ suf[r])]--;
        curp = 0;
        for(int i=1+c*len;i<=n;i++){
            curp^=arr[i];
            cntp[curp]--;
        }
    }
    vector<Query> Q(q);
    for(int i=0;i<q;i++){
        scanf("%d%d", &Q[i].l, &Q[i].r);
        Q[i].i = i;
    }
    sort(Q.begin(), Q.end(), cmp);
    int L = 1, R = 1;
    cnts[suf[1]] = 1;
    cntp[pref[1]] = 1;
    for(int i=0;i<q;i++){
        while(L > Q[i].l){
            L--;
            cnts[suf[L]]++;
            cntp[pref[L]]++;
        }
        while(L < Q[i].l){
            cnts[suf[L]]--;
            cntp[pref[L]]--;
            L++;
        }
        while(R < Q[i].r){
            R++;
            cnts[suf[R]]++;
            cntp[pref[R]]++;
        }
        while(R > Q[i].r){
            cnts[suf[R]]--;
            cntp[pref[R]]--;
            R--;
        }
        long long &cur = res[Q[i].i];
        if(id[L]==id[R]){
            for(int j=L;j<=R;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j]^k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            for(int j=L;j<=R;j++) cnts[suf[j]]++;
        }
        else{
            int j = L;
            for(;j%len!=1;j++){
                cnts[suf[j]]--;
                cur+=cnts[(suf[j]^k)];
                cur+=((suf[j] ^ suf[R + 1]) == k);
            }
            if(id[j]==id[R]){
                for(;j<=R;j++){
                    cnts[suf[j]]--;
                    cur+=cnts[(suf[j]^k)];
                    cur+=((suf[j] ^ suf[R + 1]) == k);
                }
                for(;id[j]==id[R];j--) cnts[suf[j]]++;
            }
            else{
                int lb = id[j], rb = id[j];
                while(j + len - 1 <= R){
                    rb = id[j];
                    j+=len;
                }
                cur+=b[lb][rb];
                for(j=L;j%len!=1;j++) cntp[pref[j]]--;
                int J = rb*len;
                for(j=1+J;j<=R;j++){
                    cntp[pref[j]]--;
                    cur+=cntp[(k ^ pref[j])];
                    cur+=((pref[j] ^ pref[J]) == k);
                }
                for(j=L;j%len!=1;j++) cntp[pref[j]]++;
                for(j=1+J;j<=R;j++) cntp[pref[j]]++;
            }
            for(j=L;j%len!=1;j++) cnts[suf[j]]++;
        }
    }
    for(int i=0;i<q;i++)
        printf("%lld\n", res[i]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using LL = long long;

const int N = 100100;
const int M = 2000100;
const int L = 200;

int a[N], l[M], r[M], cnt[2][N];
int n, m, k;
LL ans[M], bit[N];
bool mark[M];

vector <int> v[M], p[M], R[N];

void add(int x, int v) {
  for (int i = x; i < N; i += i & -i)
    bit[i] += v;
}

LL sum(int x) {
  LL res = 0;
  for (int i = x; i > 0; i -= i & -i)
    res += bit[i];
  return res;
}

void calc(int x) {
  memset(cnt, 0, sizeof cnt);
  for (int i = 1; i <= n; i ++) {
    cnt[0][i] = cnt[0][i - 1] + (a[i] == x);
    cnt[1][i] = cnt[1][i - 1] + ((a[i] ^ x) == k);
  }
  for (int i = 0; i < m; i ++) {
    int A = cnt[0][r[i]] - cnt[0][l[i] - 1];
    int B = cnt[1][r[i]] - cnt[1][l[i] - 1];
    if (! k)
      ans[i] += 1ll * A * (A - 1) / 2;
    else
      ans[i] += 1ll * A * B;
  }
}

int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i ++) {
    scanf("%d", a + i);
    a[i] ^= a[i - 1];
    p[a[i]].push_back(i);
  }
  for (int i = 0; i < m; i ++) {
    scanf("%d %d", l + i, r + i);
    R[r[i]].push_back(i);
  }
  for (int i = 0; i < M; i ++) {
    if (i < (i ^ k) && p[i].size() + p[i ^ k].size() > L) {
      calc(i);
      mark[i] = mark[i ^ k] = 1;
    }
  }
  v[0].push_back(0);
  for (int i = 1; i <= n; i ++) {
    if (mark[a[i]]) continue;
    for (int x : v[a[i] ^ k])
      add(x + 1, 1);
    v[a[i]].push_back(i);
    for (int id : R[i]) {
      ans[id] += sum(i) - sum(l[id] - 1);
    }
  }
  for (int i = 0; i < m; i ++)
    printf("%lld\n", ans[i]);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
using LL = long long;

const int N = 100100;
const int M = 2000100;
const int L = 200;

int a[N], l[M], r[M], cnt[2][N];
int n, m, k;
LL ans[M], bit[N];
bool mark[M];

vector <int> v[M], p[M], R[N];

void add(int x, int v) {
  for (int i = x; i < N; i += i & -i)
    bit[i] += v;
}

LL sum(int x) {
  LL res = 0;
  for (int i = x; i > 0; i -= i & -i)
    res += bit[i];
  return res;
}

void calc(int x) {
  memset(cnt, 0, sizeof cnt);
  for (int i = 1; i <= n; i ++) {
    cnt[0][i] = cnt[0][i - 1] + (a[i] == x);
    cnt[1][i] = cnt[1][i - 1] + ((a[i] ^ x) == k);
  }
  for (int i = 0; i < m; i ++) {
    int A = cnt[0][r[i]] - cnt[0][l[i] - 1];
    int B = cnt[1][r[i]] - cnt[1][l[i] - 1];
    if (! k)
      ans[i] += 1ll * A * (A - 1) / 2;
    else
      ans[i] += 1ll * A * B;
  }
}

int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i ++) {
    scanf("%d", a + i);
    a[i] ^= a[i - 1];
    p[a[i]].push_back(i);
  }
  for (int i = 0; i < m; i ++) {
    scanf("%d %d", l + i, r + i);
    R[r[i]].push_back(i);
  }
  for (int i = 0; i < M; i ++) {
    if (i <= (i ^ k) && p[i].size() + p[i ^ k].size() > L) {
      calc(i);
      mark[i] = mark[i ^ k] = 1;
    }
  }
  v[0].push_back(0);
  for (int i = 1; i <= n; i ++) {
    if (mark[a[i]]) continue;
    for (int x : v[a[i] ^ k])
      add(x + 1, 1);
    v[a[i]].push_back(i);
    for (int id : R[i]) {
      ans[id] += sum(i) - sum(l[id] - 1);
    }
  }
  for (int i = 0; i < m; i ++)
    printf("%lld\n", ans[i]);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;int n,q,x,y;map<int,pair<char,int>>m;int query(){char c;cin>>x>>y>>c;auto b=m.lower_bound(x);if(b->first==x)return 0;if(c=='L')--b;int ans=abs(b->first-x);if (b->second.first==c)ans+=b->second.second;m[x]={c,ans};return ans;}int main(){cin>>n>>q;m[0]={'U',0};m[n+1]={'L',0};for(;q;--q)cout<<query()<<'\n';}


#include <bits/stdc++.h>
using namespace std;int n,q,x,y;map<int,pair<char,int>>m;int query(){char c;cin>>x>>y>>c>>c;auto b=m.lower_bound(x);if(b->first==x)return 0;if(c=='L')--b;int ans=abs(b->first-x);if (b->second.first==c)ans+=b->second.second;m[x]={c,ans};return ans;}int main(){cin>>n>>q;m[0]={'U',0};m[n+1]={'L',0};for(;q;--q)cout<<query()<<'\n';}


#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define maxn 200010
#define maxn 752

using namespace std;

ifstream fin("comentariu.in");
ofstream fout("comentariu.out");

int arb[2][maxn],pos[2][maxn];
int x[maxn],y[maxn];
char c[maxn];
int ll,val,stop,n,q;
vector<pair<int,int> > l,u;
set<pair<int,int> > S;

void create_arb(int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (wh == 0)
            arb[wh][node] = n+1-l[left-1].first+1;
        else arb[wh][node] = n+1-u[left-1].first+1;
        return;
    }

    int mid = (left + right)/2;

    create_arb(wh,node<<1,left,mid);
    create_arb(wh,(node<<1)+1,mid+1,right);
    arb[wh][node] = min(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

void query (int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (arb[wh][node] <= val)
        {
            if (wh == 0)
                stop = l[left-1].first;
            else stop = u[left-1].first;
        }
        return;
    }

    int mid = (left+right)/2;
    if (ll <= left)
    {
        if (arb[wh][node<<1] <= val)
            query(wh,node<<1,left,mid);
        else if (arb[wh][(node<<1)+1] <= val)
            query(wh,(node<<1)+1,mid+1,right);
    }
    else
    {
        if (ll <= mid)
            query(wh,node<<1,left,mid);
        if (stop == 0)
            query(wh,(node<<1)+1,mid+1,right);
    }
}

void update (int wh, int node, int left, int right)
{
    if (left == right)
    {
        arb[wh][node] -= val;
        return;
    }

    int mid = (left + right)/2;

    if (ll <= mid)
        update(wh,node<<1,left,mid);
    else update(wh,(node<<1)+1,mid+1,right);

    arb[wh][node] = min(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

int main()
{
    fin >> n >> q;

    for (int i = 1; i <= q; ++i)
    {
        fin >> x[i] >> y[i] >> c[i];

        l.push_back(make_pair(y[i],i));
        u.push_back(make_pair(x[i],i));
    }

    sort (l.begin(), l.end(), greater<pair<int,int> >());
    sort (u.begin(), u.end(), greater<pair<int,int> >());

    for (int i = 0; i < l.size(); ++i)
        pos[0][l[i].second] = i+1;
    for (int i = 0; i < u.size(); ++i)
        pos[1][u[i].second] = i+1;

    create_arb(0,1,1,q);
    create_arb(1,1,1,q);

    for (int i = 1; i <= q; ++i)
    {
        if (S.find(make_pair(x[i],y[i])) != S.end())
        {
            cout << 0 << "\n";
            continue;
        }
        S.insert(make_pair(x[i],y[i]));

        if (c[i] == 'L')
        {
            stop = 0;
            val = y[i];
            ll = pos[1][i]+1;
            query(1,1,1,q);
            val = x[i] - stop;

            cout << val << "\n";

            ll = pos[0][i];
            update(0,1,1,q);
        }
        else
        {
            stop = 0;
            val = x[i];
            ll = pos[0][i]+1;
            query(0,1,1,q);
            val = y[i] - stop;

            cout << val << "\n";

            ll = pos[1][i];
            update(1,1,1,q);
        }
    }
}


#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define maxn 200010
using namespace std;

ifstream fin("comentariu.in");
ofstream fout("comentariu.out");

int arb[2][maxn],pos[2][maxn];
int x[maxn],y[maxn];
char c[maxn];
int ll,val,stop,n,q;
vector<pair<int,int> > l,u;
set<pair<int,int> > S;

void create_arb(int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (wh == 0)
            arb[wh][node] = n+1-l[left-1].first+1;
        else arb[wh][node] = n+1-u[left-1].first+1;
        return;
    }

    int mid = (left + right)/2;

    create_arb(wh,node<<1,left,mid);
    create_arb(wh,(node<<1)+1,mid+1,right);
    arb[wh][node] = min(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

void query (int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (arb[wh][node] <= val)
        {
            if (wh == 0)
                stop = l[left-1].first;
            else stop = u[left-1].first;
        }
        return;
    }

    int mid = (left+right)/2;
    if (ll <= left)
    {
        if (arb[wh][node<<1] <= val)
            query(wh,node<<1,left,mid);
        else if (arb[wh][(node<<1)+1] <= val)
            query(wh,(node<<1)+1,mid+1,right);
    }
    else
    {
        if (ll <= mid)
            query(wh,node<<1,left,mid);
        if (stop == 0)
            query(wh,(node<<1)+1,mid+1,right);
    }
}

void update (int wh, int node, int left, int right)
{
    if (left == right)
    {
        arb[wh][node] -= val;
        return;
    }

    int mid = (left + right)/2;

    if (ll <= mid)
        update(wh,node<<1,left,mid);
    else update(wh,(node<<1)+1,mid+1,right);

    arb[wh][node] = min(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

int main()
{
    cin >> n >> q;

    for (int i = 1; i <= q; ++i)
    {
        cin >> x[i] >> y[i] >> c[i];

        l.push_back(make_pair(y[i],i));
        u.push_back(make_pair(x[i],i));
    }

    sort (l.begin(), l.end(), greater<pair<int,int> >());
    sort (u.begin(), u.end(), greater<pair<int,int> >());

    for (int i = 0; i < l.size(); ++i)
        pos[0][l[i].second] = i+1;
    for (int i = 0; i < u.size(); ++i)
        pos[1][u[i].second] = i+1;

    create_arb(0,1,1,q);
    create_arb(1,1,1,q);

    for (int i = 1; i <= q; ++i)
    {
        if (S.find(make_pair(x[i],y[i])) != S.end())
        {
            cout << 0 << "\n";
            continue;
        }
        S.insert(make_pair(x[i],y[i]));

        if (c[i] == 'L')
        {
            stop = 0;
            val = y[i];
            ll = pos[1][i]+1;
            query(1,1,1,q);
            val = x[i] - stop;

            cout << val << "\n";

            ll = pos[0][i];
            update(0,1,1,q);
        }
        else
        {
            stop = 0;
            val = x[i];
            ll = pos[0][i]+1;
            query(0,1,1,q);
            val = y[i] - stop;

            cout << val << "\n";

            ll = pos[1][i];
            update(1,1,1,q);
        }
    }
}


#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define maxn 200010
#define maxn 752

using namespace std;

ifstream fin("comentariu.in");
ofstream fout("comentariu.out");

int arb[2][maxn],pos[2][maxn];
int x[maxn],y[maxn],c[maxn];
int ll,val,stop,n,q;
vector<pair<int,int> > l,u;

void create_arb(int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (wh == 0)
            arb[wh][node] = l[left-1].first-1;
        else arb[wh][node] = u[left-1].first-1;
        return;
    }

    int mid = (left + right)/2;

    create_arb(wh,node<<1,left,mid);
    create_arb(wh,(node<<1)+1,mid+1,right);
    arb[wh][node] = max(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

void query (int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (wh == 0)
            stop = n+1 - l[left-1].first;
        else stop = n+1 - u[left-1].first;
        return;
    }

    int mid = (left+right)/2;
    if (ll <= left)
    {
        if (arb[wh][node<<1] >= val)
            query(wh,node<<1,left,mid);
        else if (arb[wh][(node<<1)+1] >= val)
            query(wh,(node<<1)+1,mid+1,right);
    }
    else
    {
        if (ll <= mid)
            query(wh,node<<1,left,mid);
        if (stop == n+1)
            query(wh,(node<<1)+1,mid+1,right);
    }
}

void update (int wh, int node, int left, int right)
{
    if (left == right)
    {
        arb[wh][node] += val;
        return;
    }

    int mid = (left + right)/2;

    if (ll <= mid)
        update(wh,node<<1,left,mid);
    else update(wh,(node<<1)+1,mid+1,right);

    arb[wh][node] = max(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

int main()
{
    fin >> n >> q;

    for (int i = 1; i <= q; ++i)
    {
        fin >> x[i] >> y[i] >> c[i];

        l.push_back(make_pair(y[i],i));
        u.push_back(make_pair(x[i],i));
    }

    sort (l.begin(), l.end());
    sort (u.begin(), u.end());

    for (int i = 0; i < l.size(); ++i)
        pos[0][l[i].second] = i;
    for (int i = 0; i < u.size(); ++i)
        pos[1][u[i].second] = i;

    create_arb(0,1,1,q);
    create_arb(1,1,1,q);

    for (int i = 1; i <= q; ++i)
    {
        if (c[i] == 'L')
        {
            stop = n+1;
            val = y[i];
            ll = pos[1][i];
            query(1,1,1,q);
            val = stop - x[i];

            cout << val << "\n";

            ll = pos[0][i];
            update(0,1,1,q);
        }
        else
        {
            stop = n+1;
            val = x[i];
            ll = pos[0][i];
            query(0,1,1,q);
            val = stop - y[i];

            cout << val << "\n";

            ll = pos[1][i];
            update(1,1,1,q);
        }
    }
}


#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define maxn 200010
#define maxn 752

using namespace std;

ifstream fin("comentariu.in");
ofstream fout("comentariu.out");

int arb[2][maxn],pos[2][maxn];
int x[maxn],y[maxn],c[maxn];
int ll,val,stop,n,q;
vector<pair<int,int> > l,u;

void create_arb(int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (wh == 0)
            arb[wh][node] = l[left-1].first-1;
        else arb[wh][node] = u[left-1].first-1;
        return;
    }

    int mid = (left + right)/2;

    create_arb(wh,node<<1,left,mid);
    create_arb(wh,(node<<1)+1,mid+1,right);
    arb[wh][node] = max(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

void query (int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (wh == 0)
            stop = n+1 - l[left-1].first;
        else stop = n+1 - u[left-1].first;
        return;
    }

    int mid = (left+right)/2;
    if (ll <= left)
    {
        if (arb[wh][node<<1] >= val)
            query(wh,node<<1,left,mid);
        else if (arb[wh][(node<<1)+1] >= val)
            query(wh,(node<<1)+1,mid+1,right);
    }
    else
    {
        if (ll <= mid)
            query(wh,node<<1,left,mid);
        if (stop == n+1)
            query(wh,(node<<1)+1,mid+1,right);
    }
}

void update (int wh, int node, int left, int right)
{
    if (left == right)
    {
        arb[wh][node] += val;
        return;
    }

    int mid = (left + right)/2;

    if (ll <= mid)
        update(wh,node<<1,left,mid);
    else update(wh,(node<<1)+1,mid+1,right);

    arb[wh][node] = max(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

int main()
{
    cin >> n >> q;

    for (int i = 1; i <= q; ++i)
    {
        cin >> x[i] >> y[i] >> c[i];

        l.push_back(make_pair(y[i],i));
        u.push_back(make_pair(x[i],i));
    }

    sort (l.begin(), l.end());
    sort (u.begin(), u.end());

    for (int i = 0; i < l.size(); ++i)
        pos[0][l[i].second] = i;
    for (int i = 0; i < u.size(); ++i)
        pos[1][u[i].second] = i;

    create_arb(0,1,1,q);
    create_arb(1,1,1,q);

    for (int i = 1; i <= q; ++i)
    {
        if (c[i] == 'L')
        {
            stop = n+1;
            val = y[i];
            ll = pos[1][i];
            query(1,1,1,q);
            val = stop - x[i];

            cout << val << "\n";

            ll = pos[0][i];
            update(0,1,1,q);
        }
        else
        {
            stop = n+1;
            val = x[i];
            ll = pos[0][i];
            query(0,1,1,q);
            val = stop - y[i];

            cout << val << "\n";

            ll = pos[1][i];
            update(1,1,1,q);
        }
    }
}


#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define maxn 200010
using namespace std;

ifstream fin("comentariu.in");
ofstream fout("comentariu.out");

int arb[2][4*maxn],pos[2][maxn];
int x[maxn],y[maxn];
char c[maxn];
int ll,val,stop,n,q;
vector<pair<int,int> > l,u;
set<pair<int,int> > S;

void create_arb(int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (wh == 0)
            arb[wh][node] = n+1-l[left-1].first+1;
        else arb[wh][node] = n+1-u[left-1].first+1;
        return;
    }

    int mid = (left + right)/2;

    create_arb(wh,node<<1,left,mid);
    create_arb(wh,(node<<1)+1,mid+1,right);
    arb[wh][node] = min(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

void query (int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (arb[wh][node] <= val)
        {
            if (wh == 0)
                stop = l[left-1].first;
            else stop = u[left-1].first;
        }
        return;
    }

    int mid = (left+right)/2;
    if (ll <= left)
    {
        if (arb[wh][node<<1] <= val)
            query(wh,node<<1,left,mid);
        else if (arb[wh][(node<<1)+1] <= val)
            query(wh,(node<<1)+1,mid+1,right);
    }
    else
    {
        if (ll <= mid)
            query(wh,node<<1,left,mid);
        if (stop == 0)
            query(wh,(node<<1)+1,mid+1,right);
    }
}

void update (int wh, int node, int left, int right)
{
    if (left == right)
    {
        arb[wh][node] -= val;
        return;
    }

    int mid = (left + right)/2;

    if (ll <= mid)
        update(wh,node<<1,left,mid);
    else update(wh,(node<<1)+1,mid+1,right);

    arb[wh][node] = min(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

int main()
{
    cin >> n >> q;

    for (int i = 1; i <= q; ++i)
    {
        cin >> x[i] >> y[i] >> c[i];

        l.push_back(make_pair(y[i],i));
        u.push_back(make_pair(x[i],i));
    }

    sort (l.begin(), l.end(), greater<pair<int,int> >());
    sort (u.begin(), u.end(), greater<pair<int,int> >());

    for (int i = 0; i < l.size(); ++i)
        pos[0][l[i].second] = i+1;
    for (int i = 0; i < u.size(); ++i)
        pos[1][u[i].second] = i+1;

    create_arb(0,1,1,q);
    create_arb(1,1,1,q);

    for (int i = 1; i <= q; ++i)
    {
        if (S.find(make_pair(x[i],y[i])) != S.end())
        {
            cout << 0 << "\n";
            continue;
        }
        S.insert(make_pair(x[i],y[i]));

        if (c[i] == 'L')
        {
            stop = 0;
            val = y[i];
            ll = pos[1][i]+1;
            query(1,1,1,q);
            val = x[i] - stop;

            cout << val << "\n";

            ll = pos[0][i];
            update(0,1,1,q);
        }
        else
        {
            stop = 0;
            val = x[i];
            ll = pos[0][i]+1;
            query(0,1,1,q);
            val = y[i] - stop;

            cout << val << "\n";

            ll = pos[1][i];
            update(1,1,1,q);
        }
    }
}


#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define maxn 200010
#define maxn 752

using namespace std;

ifstream fin("comentariu.in");
ofstream fout("comentariu.out");

int arb[2][maxn],pos[2][maxn];
int x[maxn],y[maxn];
char c[maxn];
int ll,val,stop,n,q;
vector<pair<int,int> > l,u;
set<pair<int,int> > S;

void create_arb(int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (wh == 0)
            arb[wh][node] = n+1-l[left-1].first+1;
        else arb[wh][node] = n+1-u[left-1].first+1;
        return;
    }

    int mid = (left + right)/2;

    create_arb(wh,node<<1,left,mid);
    create_arb(wh,(node<<1)+1,mid+1,right);
    arb[wh][node] = min(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

void query (int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (arb[wh][node] <= val)
        {
            if (wh == 0)
                stop = l[left-1].first;
            else stop = u[left-1].first;
        }
        return;
    }

    int mid = (left+right)/2;
    if (ll <= left)
    {
        if (arb[wh][node<<1] <= val)
            query(wh,node<<1,left,mid);
        else if (arb[wh][(node<<1)+1] <= val)
            query(wh,(node<<1)+1,mid+1,right);
    }
    else
    {
        if (ll <= mid)
            query(wh,node<<1,left,mid);
        if (stop == 0)
            query(wh,(node<<1)+1,mid+1,right);
    }
}

void update (int wh, int node, int left, int right)
{
    if (left == right)
    {
        arb[wh][node] -= val;
        return;
    }

    int mid = (left + right)/2;

    if (ll <= mid)
        update(wh,node<<1,left,mid);
    else update(wh,(node<<1)+1,mid+1,right);

    arb[wh][node] = min(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

int main()
{
    cin >> n >> q;

    for (int i = 1; i <= q; ++i)
    {
        cin >> x[i] >> y[i] >> c[i];

        l.push_back(make_pair(y[i],i));
        u.push_back(make_pair(x[i],i));
    }

    sort (l.begin(), l.end(), greater<pair<int,int> >());
    sort (u.begin(), u.end(), greater<pair<int,int> >());

    for (int i = 0; i < l.size(); ++i)
        pos[0][l[i].second] = i+1;
    for (int i = 0; i < u.size(); ++i)
        pos[1][u[i].second] = i+1;

    create_arb(0,1,1,q);
    create_arb(1,1,1,q);

    for (int i = 1; i <= q; ++i)
    {
        if (S.find(make_pair(x[i],y[i])) != S.end())
        {
            cout << 0 << "\n";
            continue;
        }
        S.insert(make_pair(x[i],y[i]));

        if (c[i] == 'L')
        {
            stop = 0;
            val = y[i];
            ll = pos[1][i]+1;
            query(1,1,1,q);
            val = x[i] - stop;

            cout << val << "\n";

            ll = pos[0][i];
            update(0,1,1,q);
        }
        else
        {
            stop = 0;
            val = x[i];
            ll = pos[0][i]+1;
            query(0,1,1,q);
            val = y[i] - stop;

            cout << val << "\n";

            ll = pos[1][i];
            update(1,1,1,q);
        }
    }
}


#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define maxn 200010
#define maxn 752

using namespace std;

ifstream fin("comentariu.in");
ofstream fout("comentariu.out");

int arb[2][maxn],pos[2][maxn];
int x[maxn],y[maxn];
char c[maxn];
int ll,val,stop,n,q;
vector<pair<int,int> > l,u;
set<pair<int,int> > S;

void create_arb(int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (wh == 0)
            arb[wh][node] = n+1-l[left-1].first+1;
        else arb[wh][node] = n+1-u[left-1].first+1;
        return;
    }

    int mid = (left + right)/2;

    create_arb(wh,node<<1,left,mid);
    create_arb(wh,(node<<1)+1,mid+1,right);
    arb[wh][node] = min(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

void query (int wh, int node, int left, int right)
{
    if (left == right)
    {
        if (arb[wh][node] <= val)
        {
            if (wh == 0)
                stop = l[left-1].first;
            else stop = u[left-1].first;
        }
        return;
    }

    int mid = (left+right)/2;
    if (ll <= left)
    {
        if (arb[wh][node<<1] <= val)
            query(wh,node<<1,left,mid);
        else if (arb[wh][(node<<1)+1] <= val)
            query(wh,(node<<1)+1,mid+1,right);
    }
    else
    {
        if (ll <= mid)
            query(wh,node<<1,left,mid);
        if (stop == 0)
            query(wh,(node<<1)+1,mid+1,right);
    }
}

void update (int wh, int node, int left, int right)
{
    if (left == right)
    {
        arb[wh][node] -= val;
        return;
    }

    int mid = (left + right)/2;

    if (ll <= mid)
        update(wh,node<<1,left,mid);
    else update(wh,(node<<1)+1,mid+1,right);

    arb[wh][node] = min(arb[wh][node<<1], arb[wh][(node<<1)+1]);
}

int main()

    cin >> n >> q;

    for (int i = 1; i <= q; ++i)
    {
        cin >> x[i] >> y[i] >> c[i];

        l.push_back(make_pair(y[i],i));
        u.push_back(make_pair(x[i],i));
    }

    sort (l.begin(), l.end(), greater<pair<int,int> >());
    sort (u.begin(), u.end(), greater<pair<int,int> >());

    for (int i = 0; i < l.size(); ++i)
        pos[0][l[i].second] = i+1;
    for (int i = 0; i < u.size(); ++i)
        pos[1][u[i].second] = i+1;

    create_arb(0,1,1,q);
    create_arb(1,1,1,q);

    for (int i = 1; i <= q; ++i)
    {
        if (S.find(make_pair(x[i],y[i])) != S.end())
        {
            cout << 0 << "\n";
            continue;
        }
        S.insert(make_pair(x[i],y[i]));

        if (c[i] == 'L')
        {
            stop = 0;
            val = y[i];
            ll = pos[1][i]+1;
            query(1,1,1,q);
            val = x[i] - stop;

            cout << val << "\n";

            ll = pos[0][i];
            update(0,1,1,q);
        }
        else
        {
            stop = 0;
            val = x[i];
            ll = pos[0][i]+1;
            query(0,1,1,q);
            val = y[i] - stop;

            cout << val << "\n";

            ll = pos[1][i];
            update(1,1,1,q);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
struct node{long long x,y;char c;}a[200000+5];
struct node1{long long now,id;}b[200000+5];
long long Q1[200000+5],Q2[200000+5],ans[200000+5];
bool cmp(node1 A,node1 B)
{
	return A.now<B.now||A.now==B.now&&A.id<B.id;
}
bool cmp1(node1 A,node1 B)
{
	return A.now>B.now||A.now==B.now&&A.id<B.id;
}
int main()
{
	long long n,q,i,head1=0,head2=0;
	cin >> n >> q;
	for (i=1;i<=q;i++)
	{
		cin >> a[i].x >> a[i].y >> a[i].c;
		b[i].now=a[i].x;
		b[i].id=i;
	}
	sort(b+1,b+q+1,cmp);
//	for (i=1;i<=q;i++)
//		cout << b[i].id << " " << b[i].now <<endl;
	for (i=1;i<=q;i++)
	{
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='U'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='U')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].x-a[Q2[head2]].x;
			}
			else
				ans[b[i].id]=a[b[i].id].x;
		}
	}
	head1=head2=0;
	sort(b+1,b+q+1,cmp1);
	for (i=1;i<=q;i++)
	{
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='L'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='L')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].y-a[Q2[head2]].y;
			}
			else
				ans[b[i].id]=a[b[i].id].y;
		}
	}
	sort(b+1,b+q+1,cmp);
	for (i=2;i<=q;i++)
		if (b[i].now==b[i-1].now)
			ans[b[i].id]=0;
	for (i=1;i<=q;i++)
		cout << ans[i] <<endl;
}


#include<bits/stdc++.h>
using namespace std;
struct node{long long x,y;char c;}a[200000+5];
struct node1{long long now,id;}b[200000+5];
long long Q1[200000+5],Q2[200000+5],ans[200000+5];
bool cmp(node1 A,node1 B)
{
	return A.now<B.now;
}
int main()
{
	long long n,q,i,head1=0,head2=0;
	cin >> n >> q;
	for (i=1;i<=q;i++)
	{
		cin >> a[i].x >> a[i].y >> a[i].c;
		b[i].now=a[i].x;
		b[i].id=i;
	}
	sort(b+1,b+q+1,cmp);
	for (i=1;i<=q;i++)
	{
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='U'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='U')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].x-a[Q2[head2]].x;
			}
			else
				ans[b[i].id]=a[b[i].id].x;
		}
	}
	head1=head2=0;
	for (i=q;i>=1;i--)
	{
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='L'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='L')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].y-a[Q2[head2]].y;
			}
			else
				ans[b[i].id]=a[b[i].id].y;
		}
	}
	for (i=1;i<=q;i++)
		cout << ans[i] <<endl;
}


#include<bits/stdc++.h>
using namespace std;
struct node{long long x,y;char c;}a[200000+5];
struct node1{long long now,id;}b[200000+5];
long long Q1[200000+5],Q2[200000+5],ans[200000+5];
bool cmp(node1 A,node1 B)
{
	return A.now<B.now||A.now==B.now&&A.id<B.id;
}
bool cmp1(node1 A,node1 B)
{
	return A.now>B.now||A.now==B.now&&A.id<B.id;
}
int main()
{
	long long n,q,i,head1=0,head2=0;
	cin >> n >> q;
	for (i=1;i<=q;i++)
	{
		cin >> a[i].x >> a[i].y >> a[i].c;
		b[i].now=a[i].x;
		b[i].id=i;
	}
	sort(b+1,b+q+1,cmp);
	for (i=1;i<=q;i++)
	{
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='U'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='U')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].x-a[Q2[head2]].x;
			}
			else
				ans[b[i].id]=a[b[i].id].x;
		}
	}
	head1=head2=0;
	sort(b+1,b+q+1,cmp1);
	for (i=1;i<=q;i++)
	{
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='L'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='L')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].y-a[Q2[head2]].y;
			}
			else
				ans[b[i].id]=a[b[i].id].y;
		}
	}
	sort(b+1,b+q+1,cmp);
	for (i=2;i<=q;i++)
		if (b[i].now==b[i-1].now)
			ans[b[i].id]=0;
	for (i=1;i<=q;i++)
		cout << ans[i] <<endl;
}


#include<bits/stdc++.h>
using namespace std;
struct node{long long x,y;char c;}a[2000000+5];
struct node1{long long now,id;}b[2000000+5];
long long Q1[2000000+5],Q2[2000000+5],ans[2000000+5];
bool visit[2000000+5];
bool cmp(node1 A,node1 B)
{
	return A.now<B.now||A.now==B.now&&A.id<B.id;
}
bool cmp1(node1 A,node1 B)
{
	return A.now>B.now||A.now==B.now&&A.id<B.id;
}
int main()
{
	long long n,q,i,head1=0,head2=0;
	cin >> n >> q;
	for (i=1;i<=q;i++)
	{
		cin >> a[i].x >> a[i].y >> a[i].c;
		b[i].now=a[i].x;
		b[i].id=i;
	}
	sort(b+1,b+q+1,cmp);
	for (i=2;i<=q;i++)
		if (b[i].now==b[i-1].now)
			visit[b[i].id]=true;
	sort(b+1,b+q+1,cmp);
//	for (i=1;i<=q;i++)
//		cout << b[i].id << " " << b[i].now <<endl;
	for (i=1;i<=q;i++)
	{
		if (visit[b[i].id]) continue;
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='U'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='U')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].x-a[Q2[head2]].x;
			}
			else
				ans[b[i].id]=a[b[i].id].x;
		}
	}
	head1=head2=0;
	sort(b+1,b+q+1,cmp1);
	for (i=1;i<=q;i++)
	{
		if (visit[b[i].id]) continue;
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='L'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='L')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].y-a[Q2[head2]].y;
			}
			else
				ans[b[i].id]=a[b[i].id].y;
		}
	}
	sort(b+1,b+q+1,cmp);
	for (i=2;i<=q;i++)
		if (b[i].now==b[i-1].now)
			ans[b[i].id]=0;
	for (i=1;i<=q;i++)
		cout << ans[i] <<endl;
}


#include<bits/stdc++.h>
using namespace std;
struct node{long long x,y;char c;}a[200000+5];
struct node1{long long now,id;}b[200000+5];
long long Q1[200000+5],Q2[200000+5],ans[200000+5];
bool cmp(node1 A,node1 B)
{
	return A.now<B.now||A.now==B.now&&A.id<B.id;
}
bool cmp1(node1 A,node1 B)
{
	return A.now>B.now||A.now==B.now&&A.id<B.id;
}
int main()
{
	long long n,q,i,head1=0,head2=0;
	cin >> n >> q;
	for (i=1;i<=q;i++)
	{
		cin >> a[i].x >> a[i].y >> a[i].c;
		b[i].now=a[i].x;
		b[i].id=i;
	}
	sort(b+1,b+q+1,cmp);
//	for (i=1;i<=q;i++)
//		cout << b[i].id << " " << b[i].now <<endl;
	for (i=1;i<=q;i++)
	{
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='U'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='U')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].x-a[Q2[head2]].x;
			}
			else
				ans[b[i].id]=a[b[i].id].x;
		}
	}
	head1=head2=0;
	sort(b+1,b+q+1,cmp1);
	for (i=1;i<=q;i++)
	{
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='L'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='L')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].y-a[Q2[head2]].y;
			}
			else
				ans[b[i].id]=a[b[i].id].y;
		}
	}
	for (i=1;i<=q;i++)
		cout << ans[i] <<endl;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <deque>
#include <ctime>
#include <cstring>
#include <unordered_map>

//#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

#define endl '\n'

#define forr(i, n) for(ll (i) = 0LL; (i) < (n); (i)++)
#define mp3(a, b, c) mp(a, mp(b, c))

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;
typedef vector < pll > vll;

int INT_MAX_VAL = (int)  0x3F3F3F3F;
int INT_MIN_VAL = (int) -0x3F3F3F3F;
ll LONG_MAX_VAL = (ll)   0x3F3F3F3F3F3F3F3F;
ll LONG_MIN_VAL = (ll)  -0x3F3F3F3F3F3F3F3F;

#define MAXN 200006
#define MOD 1000000007

struct Query {
	ll pos;
	char d;
};

ll left_tree[2 * MAXN];
ll up_tree[2 * MAXN];

int m;

ll get_tree(ll *tree, ll v, ll q, ll tl, ll tr)
{
	if(tl == tr) {
		return tree[v];
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);

	ll med = tl + (tr - tl) / 2;
	if(q <= med) {
		return get_tree(tree, vl, q, tl, med);
	} else {
		return get_tree(tree, vr, q, med + 1, tr);
	}
}

void update_tree(ll *tree, ll v, ll val, ll l, ll r, ll tl, ll tr)
{
//	cout << val << " " << l << " " << r << endl;
	if(l > r) return;
	if(l == tl && r == tr) {
		tree[v] = val;
		return;
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);

	ll med = tl + (tr - tl) / 2;

	update_tree(tree, vl, val, l, min(med, r), tl, med);
	update_tree(tree, vr, val, max(med + 1, l), r, med + 1, tr);
}

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

	ll n; cin >> n;
	ll q; cin >> q;

	vector<Query> qs(q);

	vl vs;

	forr(i, q) {
		ll y;
		cin >> qs[i].pos >> y >> qs[i].d; qs[i].pos;
		vs.push_back(qs[i].pos);
	}

	vs.push_back(0);
	sort(vs.begin(), vs.end());
	auto it = unique(vs.begin(), vs.end());
	vs.resize(it - vs.begin());

	unordered_map<ll, ll> M;
	forr(i, vs.size()) {
		M[vs[i]] = i;
	}

	m = M.size();

	for(auto qi: qs) {
//		forr(i, 2 * m) cout << left_tree[i] << " "; cout << endl;
//		forr(i, 2 * m) cout << up_tree[i] << " "; cout << endl;

		ll pos = M[qi.pos];

//		cout << endl << pos << " " << qi.d << endl << endl;

		if(qi.d == 'U') {
			ll mx_up = get_tree(up_tree, 0, pos, 0, m - 1);
//			cout << pos << " " << m - mx_up << endl;
			update_tree(left_tree, 0, pos, pos, m - mx_up - 1, 0, m - 1);
			update_tree(up_tree, 0, pos, pos, pos, 0, m - 1);
//			cout << mx_up << " " << vs[pos] << " " << vs[mx_up] << endl;

			if(mx_up == 0) {
				cout << n + 1 - vs[pos] << endl;
			} else {
				cout << vs[mx_up] - vs[pos] << endl;
			}
		} else {
			ll mx_left = get_tree(left_tree, 0, pos, 0, m - 1);
			update_tree(up_tree, 0, pos, mx_left, pos, 0, m - 1);
			update_tree(left_tree, 0, pos, pos, pos, 0, m - 1);
//			cout << mx_left << " " << pos << endl;

//			cout << mx_left << " " << vs[mx_left] << " " << vs[pos] << endl;
//			cout << vs
			cout << vs[pos] - vs[mx_left] << endl;
		}
	}

	return 0;
}