#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
using namespace std;
// Function to factorize a number and return a map of its prime factors with their powers
unordered_map<int, int> getPrimeFactors(int num) {
unordered_map<int, int> prime_factors;
for (int i = 2; i <= sqrt(num); i++) {
while (num % i == 0) {
prime_factors[i]++;
num /= i;
}
}
if (num > 1) {
prime_factors[num]++;
}
return prime_factors;
}
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];
}
unordered_map<int, int> xFactors = getPrimeFactors(X);
// Prefix factor count map for each factor in X
unordered_map<int, vector<int>> prefixFactorCount;
for (auto &[prime, _] : xFactors) {
prefixFactorCount[prime] = vector<int>(N + 1, 0);
}
// Fill prefix factor counts
for (int i = 1; i <= N; i++) {
unordered_map<int, int> currentFactors = getPrimeFactors(A[i - 1]);
for (auto &[prime, _] : xFactors) {
prefixFactorCount[prime][i] = prefixFactorCount[prime][i - 1] + currentFactors[prime];
}
}
int Q;
cin >> Q;
while (Q--) {
int L, R;
cin >> L >> R;
L--; R--; // Adjust for 0-based indexing
bool divisible = true;
for (auto &[prime, requiredCount] : xFactors) {
int factorCountInRange = prefixFactorCount[prime][R + 1] - prefixFactorCount[prime][L];
if (factorCountInRange < requiredCount) {
divisible = false;
break;
}
}
cout << (divisible ? "Yes" : "No") << endl;
}
}
return 0;
}