//
// Light Oj - 1082 - Array Queries
// too lazy to RTE :(
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 55;
int t, n, q, l, r;
int tree[4*MAX] , a[4*MAX];
void build(int p , int st , int en){
if(st == en){
tree[p] = a[st];
return;
}
int md = (st+en)>>1;
build(p * 2 , st , md);
build(p*2+1 , md + 1 , en);
tree[p] = min(tree[p*2] , tree[p*2+1]);
}
int qwr(int p , int st ,int en){
if(st >= l && en <= r)
return tree[p];
if(st > r || en < l)
return 1000000000;
int md = (st+en)>>1;
return min(qwr(p*2 , st , md) , qwr(p*2+1 , md + 1 , en));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("input.txt", "rt", stdin);
//freopen("output.txt", "wt", stdout);
cin >> t;
for (int ti=1; ti<=t; ti++)
{
cin >> n >> q;
for (int i=0; i<n; i++)
cin >> a[i];
build(1 , 0 , n - 1);
cout << "Case " << ti << ":\n";
for (int i=0; i<q; i++)
{
cin >> l >> r;
--l;--r;
cout << qwr (1 , 0 , n - 1) << "\n";
}
}
return 0;
}
Ly8KLy8gTGlnaHQgT2ogLSAxMDgyIC0gQXJyYXkgUXVlcmllcwovLyAgdG9vIGxhenkgdG8gUlRFIDooCiAKIAojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIApjb25zdCBpbnQgTUFYID0gMWU1ICsgNTU7CmludCB0LCBuLCBxLCBsLCByOwppbnQgdHJlZVs0Kk1BWF0gLCBhWzQqTUFYXTsKIAp2b2lkIGJ1aWxkKGludCBwICwgaW50IHN0ICwgaW50IGVuKXsKICAgIGlmKHN0ID09IGVuKXsKICAgICAgICB0cmVlW3BdID0gYVtzdF07CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgaW50IG1kID0gKHN0K2VuKT4+MTsKICAgIGJ1aWxkKHAgKiAyICwgc3QgLCBtZCk7CiAgICBidWlsZChwKjIrMSAsIG1kICsgMSAsIGVuKTsKICAgIHRyZWVbcF0gPSBtaW4odHJlZVtwKjJdICwgdHJlZVtwKjIrMV0pOwp9CiAKaW50IHF3cihpbnQgcCAsIGludCBzdCAsaW50IGVuKXsKICAgIGlmKHN0ID49IGwgJiYgZW4gPD0gcikKICAgICAgICByZXR1cm4gdHJlZVtwXTsKICAgIGlmKHN0ID4gciB8fCBlbiA8IGwpCiAgICAgICAgcmV0dXJuIDEwMDAwMDAwMDA7CiAgICBpbnQgbWQgPSAoc3QrZW4pPj4xOwogICAgcmV0dXJuIG1pbihxd3IocCoyICwgc3QgLCBtZCkgLCBxd3IocCoyKzEgLCBtZCArIDEgLCBlbikpOwp9CiAKaW50IG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CiAgIAogICAgLy9mcmVvcGVuKCJpbnB1dC50eHQiLCAicnQiLCBzdGRpbik7CiAgICAvL2ZyZW9wZW4oIm91dHB1dC50eHQiLCAid3QiLCBzdGRvdXQpOwogCiAgICBjaW4gPj4gdDsKICAgIGZvciAoaW50IHRpPTE7IHRpPD10OyB0aSsrKQogICAgewogICAgICAgIGNpbiA+PiBuID4+IHE7CiAKICAgICAgICBmb3IgKGludCBpPTA7IGk8bjsgaSsrKQogICAgICAgICAgICBjaW4gPj4gYVtpXTsKIAogICAgICAgIGJ1aWxkKDEgLCAwICwgbiAtIDEpOwogCiAgICAgICAgY291dCA8PCAiQ2FzZSAiIDw8IHRpIDw8ICI6XG4iOwogICAgICAgIGZvciAoaW50IGk9MDsgaTxxOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBjaW4gPj4gbCA+PiByOwogICAgICAgICAgICAtLWw7LS1yOwogICAgICAgICAgICBjb3V0IDw8IHF3ciAoMSAsIDAgLCBuIC0gMSkgPDwgIlxuIjsKICAgICAgICB9CiAgICB9CiAKICAgIHJldHVybiAwOwp9