/*
* Copyright (c) 2024 Emon Thakur
* All rights reserved.
*/
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define life_is_a_race ios::sync_with_stdio(false); cin.tie(nullptr);
bool notprime[32002];
vector<int>allprime;
void seive()
{
for(int i=2;i<=1000;i++)
{
if(notprime[i]) continue;
for(int j=i+i;j<=32000;j+=i) notprime[j]=true;
}
for(int i=2;i<=32000;i++) {if(!notprime[i]) allprime.push_back(i);}
}
int n,x;
void combine(map<int,int>&m, map<int,int>&m1,map<int,int>&m2)
{
for(auto e:m1) m[e.first]+= e.second;
for(auto e:m2) m[e.first]+= e.second;
}
void buildsg(int node,int start,int end,vector<int>&a,vector<map<int,int>>&sg,map<int,int>&mx)
{
if(start == end)
{
for(auto e:mx)
{
while(a[start] % e.first == 0)
{
sg[node][e.first] ++;
a[start] /= e.first;
}
}
return;
}
int mid = (start+end)/2;
buildsg(node*2,start,mid,a,sg,mx);
buildsg(node*2+1,mid+1,end,a,sg,mx);
combine(sg[node],sg[node*2],sg[node*2+1]);
}
map<int,int> query(int node,int start,int end,int l,int r,vector<map<int,int>>&sg)
{
map<int,int> m;
if(l>end || r<start) return m;
if(l<=start && r>=end) return sg[node];
int mid = (start+end)/2;
map<int,int> m1 = query(node*2,start,mid,l,r,sg);
map<int,int> m2 = query(node*2+1,mid+1,end,l,r,sg);
combine(m,m1,m2);
return m;
}
int main()
{
life_is_a_race;
seive();
int t; cin>>t; while(t--)
{
//cout<<"Case "<<tc<<": ";
cin >> n >> x;
vector<int> a(n+1);
for(int i=0;i<n;i++) cin>>a[i];
map<int,int> mx;
for(auto e:allprime)
{
if(e>x) break;
while(x%e==0)
{
mx[e]++;
x /= e;
}
}
if(x > 1) mx[x]++;
vector<map<int,int>> sg(4*n+5);
buildsg(1,0,n-1,a,sg,mx);
int q; cin>>q; while(q--)
{
int l,r; cin>>l>>r;
map<int,int> m = query(1,0,n-1,l-1,r-1,sg);
bool ok = true;
for(auto e:mx)
{
if(m[e.first] < e.second)
{
ok = false;
break;
}
}
if(ok) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
}