#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl "\n"
#define FF ios_base::sync_with_stdio(0);cin.tie(0)
#define binary(value, size) cout << bitset<size>(value) << '\n'
#define Tp template<class T>
#define Tpp template<typename T>
#define Tppp template<typename T1,typename T2>
#define eps 1e-9
#define pf printf
#define sf scanf
#define clr(arr,val) memset((arr),val,(sizeof(arr)))
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define all(v) (v).begin(),(v).end()
#define asort(a) sort(a.begin(),a.end())
#define arev(a) reverse(a.begin(),a.end())
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define V vector
#define P pair
#define M map
#define mt make_tuple
#define BS(v,x) binary_search(v.begin(),v.end(),x) //return true /false
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()//found and that value and not found than greater value pos
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin() //found and greater value pos && not found also greater pos
#define sma(c) towlower(c)
#define rt(x) sqrt(x)
#define cap(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define SUM(v) accumulate (v.begin(),v.end(),0)//sum of the vector
#define MAX(v) *max_element(v.begin(),v.end())//max element of the vector
#define MIN(v) *min_element(v.begin(),v.end())//min element of the vector
#define SZ(x) long long int(x.size())
#define Ceil(n) (long long int)ceil(n)
#define Floor(n) (long long int)floor(n)
#define deb(x) cout << #x << " = " << x << "\n";
#define deb2(x,y) cout << #x << " = " << x << ", "; cout << #y << " = " << y << "\n";
#define deb3(x,y,z) cout << #x << " = " << x << ", "; cout << #y << " = " << y << ", "; cout << #z << " = " << z << "\n";
#define deb4(x,y,z,r) cout << #x << " = " << x << ", "; cout << #y << " = " << y << ", "; cout << #z << " = " << z << ", ";cout << #r << " = " << r << "\n";
#define out(ans) cout<<ans<<"\n"
#define outs(ans) cout<<ans<<" "<<"\n"
#define FI freopen ("in.txt", "r", stdin)
#define FO freopen ("out.txt", "w", stdout)
using namespace std;
//using namespace __gnu_pbds;
typedef int ll;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll> > v2d;
typedef vector<vector<vector<ll> > > v3d;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef map<ll,ll> mpl;
typedef priority_queue<ll> heap;// heap max value from top
typedef priority_queue<ll, vector<ll>, greater<ll> > revheap;//heap min value from top
bool Check(int N,int pos)
{
return (bool)(N & (1<<pos));
}
int Set(int N,int pos)
{
return N=N | (1<<pos);
}
const int mx=1e6+10;
int status[(mx/32)+2];
ll N=mx;
vll primes;
void sieve()
{
memset(status,0,sizeof(status));
int i, j, sqrtN;
sqrtN = int( sqrt( N ) );
for( i = 3; i <= sqrtN; i += 2 )
{
if( Check(status[i>>5],i&31)==0)
{
for(j = i*i; j <= N; j += (i<<1) )
{
status[j>>5]=Set(status[j>>5],j & 31) ;
}
}
}
primes.pb(2);
for(i=3;i<=N;i+=2)
if( Check(status[i>>5],i&31)==0) primes.pb(i);
//deb(primes.size());
}
map<ll,vll>mm,vali;
void factorize(ll idx,ll n )
{
//vll factors;
ll sqrtn = sqrt ( n );
ll r=primes.size();
//deb(n);
for ( ll i = 0; i <r && primes[i] <= sqrtn; i++ )
{
if ( n % primes[i] == 0 )
{
ll xg=0;
while ( n % primes[i] == 0 )
{
xg++;
n /= primes[i];
//freq[primes[i]]++;
}
ll pp=vali[primes[i]].size();
ll last;
if(pp==0) last=0;
else last=vali[primes[i]][pp-1];
vali[primes[i]].pb(last+xg);
mm[primes[i]].pb(idx);
//deb2(primes[i],xg);
//factors.pb(primes[i]);
sqrtn = sqrt ( n );
}
}
if ( n != 1 )
{
ll pp=vali[n].size();
ll last;
if(pp==0) last=0;
else last=vali[n][pp-1];
mm[n].pb(idx);
vali[n].pb(last+1);
}
// ll q=factors.size();
// for(ll i=0;i<q;i++)
// {
// if(i!=q-1)cout<<factors[i]<<"^"<<freq[factors[i]]<<" ";
// else cout<<factors[i]<<"^"<<freq[factors[i]];
// }
// cout<<endl;
}
vpll temp;
void factorize2(ll n)
{
//vll factors;
//vpll temp;
ll sqrtn = sqrt ( n );
ll r=primes.size();
for ( ll i = 0; i <r && primes[i] <= sqrtn; i++ )
{
if ( n % primes[i] == 0 )
{ ll xx=0;
while ( n % primes[i] == 0 )
{
xx++;
n /= primes[i];
//freq[primes[i]]++;
}
temp.pb({primes[i],xx});
//temp[{primes[i],xx}].pb(i);
//factors.pb(primes[i]);
sqrtn = sqrt ( n );
}
}
if ( n != 1 )
{
temp.pb({n,1});
}
//return temp;
// ll q=factors.size();
// for(ll i=0;i<q;i++)
// {
// if(i!=q-1)cout<<factors[i]<<"^"<<freq[factors[i]]<<" ";
// else cout<<factors[i]<<"^"<<freq[factors[i]];
// }
// cout<<endl;
}
void S()
{
mm.clear();
vali.clear();
temp.clear();
ll n,x;cin>>n>>x;
vll v(n);
rep(i,0,n)
{
cin>>v[i];factorize(i,v[i]);
}
//return;
ll q;cin>>q;
factorize2(x);
//return;
//return;
rep(i,0,q)
{
ll left,right;cin>>left>>right;
left--;right--;
//return;
bool ff=1;
for(auto xx:temp)
{
//deb2(xx.F,xx.S);
//return;
auto it=lower_bound(all(mm[xx.F]),left);
auto it2=upper_bound(all(mm[xx.F]),right);
if(it2==mm[xx.F].begin())
{
ff=0;break;
}
ll baad=0;
if(it==mm[xx.F].begin())
{
baad=0;
}
else
{
it--;
ll pos=it-mm[xx.F].begin();
baad=vali[xx.F][pos];
}
it2--;
ll ase;
ll pos2=it2-mm[xx.F].begin();
if(pos2>=0) ase=vali[xx.F][pos2]-baad;
else
{
ff=0;break;
}
//deb(pos);
if(ase<xx.S)
{
ff=0;break;
}
}
if(ff) cout<<"Yes\n";
else cout<<"No\n";
}
}
int main()
{
FF;
sieve();
ll tc;cin>>tc;
while(tc--)
{
S();
}
return 0;
}