#include <bits/stdc++.h>
using namespace std;
const int logn = 32, maxn = logn * 2e5 + 42;
int cnt[maxn], to[maxn][2];
int rt[maxn];
int sz = 1;
void copy(int x)
{
to[sz][0] = to[x][0];
to[sz][1] = to[x][1];
cnt[sz] = cnt[x] + 1;
}
void upd(int v, unsigned n)
{
n ^= 1u << logn - 1;
v++;
copy(rt[v - 1]);
v = rt[v] = sz++;
for(int i = logn - 1; i >= 0; i--)
{
int c = (n >> i) & 1;
copy(to[v][c]);
v = to[v][c] = sz++;
}
}
unsigned find_by_order(int l, int r, int k)
{
l = rt[l];
r = rt[r];
unsigned ans = 0;
for(int i = logn - 1; i >= 0; i--)
{
int c = 0;
if(cnt[to[r][0]] - cnt[to[l][0]] < k)
{
k -= cnt[to[r][0]] - cnt[to[l][0]];
ans |= 1u << i;
c = 1;
}
l = to[l][c];
r = to[r][c];
}
return ans;
}
main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int nw[n];
for(int i = 0; i < n; i++)
cin >> nw[i];
for(int i = 0; i < n; i++)
upd(i, nw[i]);
while(m--)
{
int l, r, k;
cin >> l >> r >> k;
cout << (int)(find_by_order(l - 1, r, k) ^ (1u << logn - 1)) << "\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKIGNvbnN0IGludCBsb2duID0gMzIsIG1heG4gPSBsb2duICogMmU1ICsgNDI7CmludCBjbnRbbWF4bl0sIHRvW21heG5dWzJdOwppbnQgcnRbbWF4bl07CmludCBzeiA9IDE7Cgp2b2lkIGNvcHkoaW50IHgpCiB7CiAgICB0b1tzel1bMF0gPSB0b1t4XVswXTsKICAgIHRvW3N6XVsxXSA9IHRvW3hdWzFdOwogICAgY250W3N6XSA9IGNudFt4XSArIDE7CiB9Cgp2b2lkIHVwZChpbnQgdiwgdW5zaWduZWQgbikKIHsKICAgIG4gXj0gMXUgPDwgbG9nbiAtIDE7CiAgICB2Kys7CiAgICBjb3B5KHJ0W3YgLSAxXSk7CiAgICB2ID0gcnRbdl0gPSBzeisrOwogICAgZm9yKGludCBpID0gbG9nbiAtIDE7IGkgPj0gMDsgaS0tKQogICAgewogICAgICAgIGludCBjID0gKG4gPj4gaSkgJiAxOwogICAgICAgIGNvcHkodG9bdl1bY10pOwogICAgICAgIHYgPSB0b1t2XVtjXSA9IHN6Kys7CiAgICB9CiB9Cgp1bnNpZ25lZCBmaW5kX2J5X29yZGVyKGludCBsLCBpbnQgciwgaW50IGspCiB7CiAgICBsID0gcnRbbF07CiAgICByID0gcnRbcl07CiAgICB1bnNpZ25lZCBhbnMgPSAwOwogICAgZm9yKGludCBpID0gbG9nbiAtIDE7IGkgPj0gMDsgaS0tKQogICAgewogICAgCWludCBjID0gMDsKICAgICAgICBpZihjbnRbdG9bcl1bMF1dIC0gY250W3RvW2xdWzBdXSA8IGspCiAgICAgICAgewogICAgICAgICAgICBrIC09IGNudFt0b1tyXVswXV0gLSBjbnRbdG9bbF1bMF1dOwogICAgICAgICAgICBhbnMgfD0gMXUgPDwgaTsKICAgICAgICAgICAgYyA9IDE7CiAgICAgICAgfQogICAgICAgIGwgPSB0b1tsXVtjXTsKICAgICAgICByID0gdG9bcl1bY107CiAgICB9CiAgICByZXR1cm4gYW5zOwogfQoKIG1haW4oKQogewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwogICAgaW50IG4sIG07CiAgICBjaW4gPj4gbiA+PiBtOwogICAgaW50IG53W25dOwogICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgICAgICBjaW4gPj4gbndbaV07CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgICAgIHVwZChpLCBud1tpXSk7CiAgICB3aGlsZShtLS0pCiAgICB7CiAgICAgICAgaW50IGwsIHIsIGs7CiAgICAgICAgY2luID4+IGwgPj4gciA+PiBrOwogICAgICAgIGNvdXQgPDwgKGludCkoZmluZF9ieV9vcmRlcihsIC0gMSwgciwgaykgXiAoMXUgPDwgbG9nbiAtIDEpKSA8PCAiXG4iOwogICAgfQogfQo=