#include "bits/stdc++.h"
using namespace std;
using ll=long long;
void solve();
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cout << setprecision(8) << fixed;
int t=1;
cin>>t;
for(int i=1;i<=t;i++){
// cout<<"Test case# "<<i<<" ";
solve();
}
return 0;
}
void solve(){
ll n,x;cin>>n>>x;
vector<ll>a(n);
for(int i=0;i<n;i++)cin>>a[i];
ll K=25;
ll st[K][n+1];
std::copy(a.begin(), a.end(), st[0]);
for (int i = 1; i <= K; i++)
for (int j = 0; j + (1 << i) <= n; j++)
st[i][j] = (st[i - 1][j]* st[i - 1][j + (1 << (i - 1))])%x;
ll q;cin>>q;
while(q--){
ll l,r;cin>>l>>r;
ll prod=1;
l--,r--;
for(int i=K;i>=0;i--){
if((1<<i)<=(r-l+1)){
prod=(prod%x*st[i][l]%x)%x;
l+=(1<<i);
}
}
// cout<<prod<<endl;
if(prod%x==0){
cout<<"Yes"<<'\n';
}else{
cout<<"No"<<'\n';
}
}
}