# Untitled

unknown
plain_text
13 days ago
1.4 kB
0
Indexable
Never
#pragma GCC optimize("O2,no-stack-protector,unroll-loops")
#define ll long long
#define pb push_back
#define ipar(arr, n) vector<ll> arr(n); for(int i=0;i<n;i++) cin>>arr[i];
#include <cmath>
#include <bits/stdc++.h>
#define pii pair<int, int>;
#define pll pair<ll, ll>;
using namespace std;

void solve(){
ll n;cin>>n; ipar(arr,n);
/*  vector<ll>leq(n,-1); //uneq[i] stores the index of uneqaul no just before i

//O(N2)
for(ll i=1;i<n;i++){
for(ll j=i-1;j>=0;j--){
if(arr[j]!=arr[i]) {
leq[i]=j;
break;
}
}
}
*/
//O(N)
vector<ll>uneq(n,-1);
ll largind=-1;
for(ll i=1;i<n;i++){
if(arr[i]==arr[i-1]){
uneq[i]=largind;
}
else{
largind=i-1;
uneq[i]=largind;
}
}
//for(auto i:uneq) cout<<i<<" ";
ll q; cin>>q;
while(q--){
ll l,r; cin>>l>>r;
l--,r--;
//cout<<"--------------------"<<"\n";
bool found=false;
if(uneq[r]!=-1 && uneq[r]>=l){ // theres a unequal no available an it's within l
cout<<uneq[r]+1<<" "<<r+1<<"\n";
found=true;
}

if(!found) cout<<-1<<" "<<-1<<"\n";
}
}

signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--) solve();
}