#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=998244353;
typedef long long ll;
#define debug(x) cout<<x<<endl
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
    	int n,x;
    	cin>>n>>x;
    	vector<int>a(n+1);
    	for(int i=1;i<=n;i++)cin>>a[i];
    	map<int,int>p;
    	for(int i=2;i<=sqrt(x);i++){
    		while(x>1 && x%i==0){
    			p[i]++;
    			x/=i;
    		}
    	}
    	vector<map<int,int>>prefix(n+2);
    	for(int i=1;i<=n;i++){
    		for(auto it:p){
    			prefix[i][it.first]=prefix[i-1][it.first];
    			while(a[i]%it.first==0){
    				prefix[i][it.first]++;
    				a[i]/=it.first;
    			}
    		}
    		
    	}
    	int q;
    	cin>>q;
    	while(q--){
    		int l,r;
    		cin>>l>>r;
    		l--;
    		int ok=1;
    		for(auto i:p){
    			int total=prefix[r][i.first]-prefix[l][i.first];
    			ok&=(total>=i.second);
    		}
    		cout<<(ok?"Yes\n":"No\n");
    	}
    	
    	
    	
    }
    
    
    return 0;
 
}