#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
// Function to perform prime factorization
map<int, int> primeFactorization(int num) {
map<int, int> factors;
while (num % 2 == 0) {
factors[2]++;
num /= 2;
}
for (int i = 3; i <= sqrt(num); i += 2) {
while (num % i == 0) {
factors[i]++;
num /= i;
}
}
if (num > 2) {
factors[num]++;
}
return factors;
}
// Main function to solve the problem
int main() {
int T;
cin >> T;
while (T--) {
int N, X;
cin >> N >> X;
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
// Prime factorization of X
map<int, int> xFactors = primeFactorization(X);
// Create prefix factorization maps for array A
vector<map<int, int>> prefixFactors(N + 1);
for (int i = 0; i < N; ++i) {
map<int, int> currentFactors = primeFactorization(A[i]);
prefixFactors[i + 1] = prefixFactors[i]; // Start with the previous prefix
for (const auto& factor : currentFactors) {
prefixFactors[i + 1][factor.first] += factor.second;
}
}
int Q;
cin >> Q;
while (Q--) {
int L, R;
cin >> L >> R;
L--; R--; // Convert to 0-based index
bool divisible = true;
for (const auto& factor : xFactors) {
int prime = factor.first;
int requiredPower = factor.second;
// Calculate the count of this prime in the subarray product
int powerInSubarray = prefixFactors[R + 1][prime] - prefixFactors[L][prime];
if (powerInSubarray < requiredPower) {
divisible = false;
break;
}
}
if (divisible) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
return 0;
}