#include <bits/stdc++.h>
using namespace std;
#define int register unsigned
signed main(){
freopen("bamboo.in","r",stdin);
freopen("bamboo.out","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T,n,q;
int ans;
cin>>T;
while (T--){
cin>>n;
int f[16]={0};
int t[16000]={0};
for (int i=1;i<=n;i++){
int x;
cin>>x;
t[f[x]]=i;
f[x]=i;
}
cin>>q;
while (q--){
int l,r;
ans=0;
cin>>l>>r;
for (int i=l;i<=r;i++){
if (t[i]<l||t[i]>r) ans++;
else i=t[i];
}
cout<<ans<<'\n';
}
}
return 0;
}