//
// Light Oj - 1082 - Array Queries
// too lazy to RTE :(
#include <bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d" , &a)
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()
{
//freopen("input.txt", "rt", stdin);
//freopen("output.txt", "wt", stdout);
sc(t);
for (int ti=1; ti<=t; ti++)
{
sc(n);sc(q);
for (int i=0; i<n; i++)
sc(a[i]);
build(1 , 0 , n - 1);
cout << "Case " << ti << ":\n";
for (int i=0; i<q; i++)
{
sc(l);sc(r);
--l;--r;
cout << qwr (1 , 0 , n - 1) << "\n";
}
}
return 0;
}
Ly8KLy8gTGlnaHQgT2ogLSAxMDgyIC0gQXJyYXkgUXVlcmllcwovLyAgdG9vIGxhenkgdG8gUlRFIDooCiAKIAojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBzYyhhKSBzY2FuZigiJWQiICwgJmEpCiAKY29uc3QgaW50IE1BWCA9IDFlNSArIDU1OwppbnQgdCwgbiwgcSwgbCwgcjsKaW50IHRyZWVbNCpNQVhdICwgYVs0Kk1BWF07CiAKdm9pZCBidWlsZChpbnQgcCAsIGludCBzdCAsIGludCBlbil7CiAgICBpZihzdCA9PSBlbil7CiAgICAgICAgdHJlZVtwXSA9IGFbc3RdOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGludCBtZCA9IChzdCtlbik+PjE7CiAgICBidWlsZChwICogMiAsIHN0ICwgbWQpOwogICAgYnVpbGQocCoyKzEgLCBtZCArIDEgLCBlbik7CiAgICB0cmVlW3BdID0gbWluKHRyZWVbcCoyXSAsIHRyZWVbcCoyKzFdKTsKfQogCmludCBxd3IoaW50IHAgLCBpbnQgc3QgLGludCBlbil7CiAgICBpZihzdCA+PSBsICYmIGVuIDw9IHIpCiAgICAgICAgcmV0dXJuIHRyZWVbcF07CiAgICBpZihzdCA+IHIgfHwgZW4gPCBsKQogICAgICAgIHJldHVybiAxMDAwMDAwMDAwOwogICAgaW50IG1kID0gKHN0K2VuKT4+MTsKICAgIHJldHVybiBtaW4ocXdyKHAqMiAsIHN0ICwgbWQpICwgcXdyKHAqMisxICwgbWQgKyAxICwgZW4pKTsKfQogCmludCBtYWluKCkKewogCiAgIAogICAgLy9mcmVvcGVuKCJpbnB1dC50eHQiLCAicnQiLCBzdGRpbik7CiAgICAvL2ZyZW9wZW4oIm91dHB1dC50eHQiLCAid3QiLCBzdGRvdXQpOwogCiAgICBzYyh0KTsKICAgIGZvciAoaW50IHRpPTE7IHRpPD10OyB0aSsrKQogICAgewogICAgICAgIHNjKG4pO3NjKHEpOwogCiAgICAgICAgZm9yIChpbnQgaT0wOyBpPG47IGkrKykKICAgICAgICAgICAgc2MoYVtpXSk7CiAKICAgICAgICBidWlsZCgxICwgMCAsIG4gLSAxKTsKIAogICAgICAgIGNvdXQgPDwgIkNhc2UgIiA8PCB0aSA8PCAiOlxuIjsKICAgICAgICBmb3IgKGludCBpPTA7IGk8cTsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgc2MobCk7c2Mocik7CiAgICAgICAgICAgIC0tbDstLXI7CiAgICAgICAgICAgIGNvdXQgPDwgcXdyICgxICwgMCAsIG4gLSAxKSA8PCAiXG4iOwogICAgICAgIH0KICAgIH0KIAogICAgcmV0dXJuIDA7Cn0=