#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll *seg , *arr , *lazy;
void build(ll low , ll high , ll pos){
if(low>high)return;
if(low == high){
seg[pos] = arr[low];
return;
}
int mid = (low + high)/2;
build(low , mid , 2*pos);
build(mid+1 , high , 2*pos+1);
seg[pos] = min(seg[2*pos] , seg[2*pos+1]);
}
ll query(ll low , ll high , ll qlow , ll qhigh , ll pos){
if(qlow>high || qhigh<low || low >high)return INT_MAX;
if(qlow<=low && qhigh>=high)return seg[pos];
ll mid = (low+high)/2;
return min(query(low , mid , qlow , qhigh , 2*pos) , query(mid+1 , high , qlow , qhigh , 2*pos+1));
}
void init(ll n){
arr = new ll[n];
seg = new ll[4*n];
//memset(seg , 0 , sizeof(seg));
//memset(arr , 0 , sizeof(arr));
}
int main(){
// #ifndef check
// freopen("input.txt" , "r" , stdin);
// #endif
ios::sync_with_stdio(0);
cin.tie(0);
int t;cin>>t;
for(int tc = 1; tc <=t ; tc++){
cout<<"Scenario #"<<tc<<":"<<'\n';
ll i,n,q;cin>>n>>q;
init(n+5);
for(i=0;i<n;i++)cin>>arr[i];
build(0 , n-1 , 1);
while(q--){
ll low , high;
cin>>low>>high;
cout<<query(0 , n-1 , low-1 , high-1 , 1)<<'\n';
}
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgbGw7CiAKbGwgKnNlZyAsICphcnIgLCAqbGF6eTsKIAp2b2lkIGJ1aWxkKGxsIGxvdyAsIGxsIGhpZ2ggLCBsbCBwb3MpewogCglpZihsb3c+aGlnaClyZXR1cm47CiAKCWlmKGxvdyA9PSBoaWdoKXsKCQlzZWdbcG9zXSA9IGFycltsb3ddOwoJCXJldHVybjsKCX0KIAoJaW50IG1pZCA9IChsb3cgKyBoaWdoKS8yOwogCglidWlsZChsb3cgLCBtaWQgLCAyKnBvcyk7CglidWlsZChtaWQrMSAsIGhpZ2ggLCAyK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