/**
*
* Author: MARS
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000010;
unordered_map<ll,int>frq;
vector<pair<ll,int>>pr;
int ans=0;
void f(int i, ll x){
if(i == pr.size()){
ans+=frq[x];
return ;
}
int p=pr[i].second;
ll y=1;
for(int j=0 ; j<=p ; j++){
f(i+1, x*y);
y*=pr[i].first;
}
}
int main(){
int n;
scanf("%d",&n);
for(int i=0 ; i<n ; i++){
ll x;
scanf("%lld",&x);
frq[x]++;
}
int q;
scanf("%d",&q);
for(int qn=1 ; qn<=q ; qn++){
ll k;
scanf("%lld",&k);
pr.clear();
for(ll i=2 ; i*i*i<=k ; i++){
int cnt=0;
while(k%i == 0){
cnt++;
k/=i;
}
if(cnt)
pr.push_back({i, cnt});
}
if(k > 1)
pr.push_back({sqrt(k), 2});
ans=0;
f(0,1);
printf("Query %d: %d\n",qn,ans);
}
}
LyoqCioKKiBBdXRob3I6IE1BUlMKKiBMYW5nOiBHTlUgQysrMTQKKgoqKi8KCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmNvbnN0IGludCBOPTEwMDAwMTA7CnVub3JkZXJlZF9tYXA8bGwsaW50PmZycTsKdmVjdG9yPHBhaXI8bGwsaW50Pj5wcjsKaW50IGFucz0wOwoKdm9pZCBmKGludCBpLCBsbCB4KXsKICAgIGlmKGkgPT0gcHIuc2l6ZSgpKXsKICAgICAgICBhbnMrPWZycVt4XTsKICAgICAgICByZXR1cm4gOwogICAgfQoKICAgIGludCBwPXByW2ldLnNlY29uZDsKICAgIGxsIHk9MTsKCiAgICBmb3IoaW50IGo9MCA7IGo8PXAgOyBqKyspewogICAgICAgIGYoaSsxLCB4KnkpOwogICAgICAgIHkqPXByW2ldLmZpcnN0OwogICAgfQp9CgppbnQgbWFpbigpewogICAgaW50IG47CiAgICBzY2FuZigiJWQiLCZuKTsKICAgIGZvcihpbnQgaT0wIDsgaTxuIDsgaSsrKXsKICAgICAgICBsbCB4OwogICAgICAgIHNjYW5mKCIlbGxkIiwmeCk7CiAgICAgICAgZnJxW3hdKys7CiAgICB9CgogICAgaW50IHE7CiAgICBzY2FuZigiJWQiLCZxKTsKICAgIGZvcihpbnQgcW49MSA7IHFuPD1xIDsgcW4rKyl7CiAgICAgICAgbGwgazsKICAgICAgICBzY2FuZigiJWxsZCIsJmspOwogICAgICAgIHByLmNsZWFyKCk7CiAgICAgICAgZm9yKGxsIGk9MiA7IGkqaSppPD1rIDsgaSsrKXsKICAgICAgICAgICAgaW50IGNudD0wOwogICAgICAgICAgICB3aGlsZShrJWkgPT0gMCl7CiAgICAgICAgICAgICAgICBjbnQrKzsKICAgICAgICAgICAgICAgIGsvPWk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoY250KQogICAgICAgICAgICAgICAgcHIucHVzaF9iYWNrKHtpLCBjbnR9KTsKICAgICAgICB9CgogICAgICAgIGlmKGsgPiAxKQogICAgICAgICAgICBwci5wdXNoX2JhY2soe3NxcnQoayksIDJ9KTsKCiAgICAgICAgYW5zPTA7CiAgICAgICAgZigwLDEpOwogICAgICAgIHByaW50ZigiUXVlcnkgJWQ6ICVkXG4iLHFuLGFucyk7CiAgICB9Cgp9Cg==