#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define error1(x) cerr<<#x<<" = "<<(x)<<endl
#define error2(a,b) cerr<<"("<<#a<<", "<<#b<<") = ("<<(a)<<", "<<(b)<<")\n";
#define coutall(v) for(auto &it: v) cout << it << " "; cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e5 + 3;
void add_prime_factors(int n, map<int, int> &mp) { // O(sqrt(n))
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
mp[i] += 1;
n /= i;
}
}
if (n > 1) mp[n] += 1;
return;
}
struct Merge_Sort_Tree {
vector<map<int, int>> t;
Merge_Sort_Tree() {
t.resize(4 * N, {});
}
void build(int node, int st, int en, vector<int> &arr) { //=> O(N log N)
t[node].clear();
if (st == en) {
// t[node] = {arr[st]};
add_prime_factors(arr[st], t[node]);
return;
}
int mid = (st + en) >> 1;
build(node << 1, st, mid, arr); // divide left side
build(node << 1 | 1, mid + 1, en, arr); // divide right side
// Merging left and right portion
auto &Cur = t[node];
auto &Left = t[node << 1];
auto &Right = t[node << 1 | 1];
for(auto &[i, j]: Left) Cur[i] = j;
for(auto &[i, j]: Right) Cur[i] += j;
}
map<int, int> emp;
map<int, int> query(int node, int st, int en, int l, int r) { //=> O(log N * log N)
// assert(l <= r); // <==
if (st > r || en < l) { // No overlapping and out of range
return emp; // <== careful
}
if (l <= st && en <= r) { // Complete overlapped (l-r in range)
return t[node];
}
// Partial overlapping
int mid = (st + en) >> 1;
auto Left = query(node << 1, st, mid, l, r);
auto Right = query(node << 1 | 1, mid + 1, en, l, r);
map<int, int> Cur;
for(auto &[i, j]: Left) Cur[i] = j;
for(auto &[i, j]: Right) Cur[i] += j;
return Cur;
}
} st1;
void prime_factors(int n, vector<int> &pf) { // O(sqrt(n))
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
pf.push_back(i);
n /= i;
}
}
if (n > 1) pf.push_back(n);
return;
}
void solve() {
int n, x, q;
cin >> n >> x;
vector<int> pf;
prime_factors(x, pf);
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
st1.build(1, 0, n - 1, v);
cin >> q;
int l, r;
while(q--) {
cin >> l >> r; --l, --r;
map<int, int> mp = st1.query(1, 0, n - 1, l, r);
bool ok = 1;
for(auto &i: pf) {
if(mp[i] == 0) {
ok = 0;
break;
}
mp[i] -= 1;
}
if(ok) yes;
else no;
}
return;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int tc = 1;
cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case " << t << ": ";
solve();
}
return 0;
}