#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define LagaKar ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second
#define precise(ans) cout<<fixed<<setprecision(15)<<ans
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define sz(x) ((ll)(x).size())
#define all(x) x.begin(), x.end()
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define MOD1 998244353
typedef long long ll; typedef unsigned long long ull; typedef long double lld; typedef pair<ll, ll> pii; typedef pair<ll, ll> pl; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<pii> vpii; typedef vector<pl> vpl; template <typename T> using prq_mx = priority_queue<T>; template <typename T> using prq_mn = priority_queue<T, vector<T>, greater<T>>;
const double eps = 1e-9; const ll INF = (ll) 1e9; const ll inf64 = 2e18; const ll INF64 = 9e18;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _prll(x); cerr << endl;
#else
#define debug(x)
#endif
void _prll(ll t) {cerr << t;} void _print(ll t) {cerr << t;} void _prll(string t) {cerr << t;} void _prll(char t) {cerr << t;} void _prll(lld t) {cerr << t;} void _prll(double t) {cerr << t;} void _prll(ull t) {cerr << t;} template <class T, class V> void _prll(pair <T, V> p); template <class T> void _prll(vector <T> v); template <class T> void _prll(set <T> v); template <class T, class V> void _prll(map <T, V> v); template <class T> void _prll(multiset <T> v); template <class T, class V> void _prll(pair <T, V> p) {cerr << "{"; _prll(p.fi); cerr << ","; _prll(p.se); cerr << "}";} template <class T> void _prll(vector <T> v) {cerr << "[ "; for (T i : v) {_prll(i); cerr << " ";} cerr << "]";} template <class T> void _prll(set <T> v) {cerr << "[ "; for (T i : v) {_prll(i); cerr << " ";} cerr << "]";} template <class T> void _prll(multiset <T> v) {cerr << "[ "; for (T i : v) {_prll(i); cerr << " ";} cerr << "]";} template <class T, class V> void _prll(map <T, V> v) {cerr << "[ "; for (auto i : v) {_prll(i); cerr << " ";} cerr << "]";}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//////////////////////////////////////////////////////////////////////////////////
const ll max_N=1e6+10;
vector<ll> prime(max_N, 0);
vector<ll> aa;
void primesieve(){
prime[0] = 1;
prime[1] = 1;
for (ll i = 2; i <max_N; i++)
{
if (prime[i] == 0)
{
prime[i]=i;
for (ll j = i*i; j < max_N; j = j + i)
{
prime[j] = i;
}
}
}
for(ll i=2;i<max_N;i++){
if(prime[i]){
aa.push_back(i);
}
}
}
void chal(){
ll n;
cin>>n;
vl aa(n);
map<ll,ll> bb;
ll ans=0;
fo(i,n){
cin>>aa[i];
ll x=aa[i];
ll res=1;
while(x>1){
ll p=prime[x];
if(p==0){
// cout<<x<<" "<<-1<<endl;
exit(0);
}
ll c=0;
while(x>1 && x%p==0){
x=x/p;
c++;
}
if((c&1)){
res*=p;
}
}
bb[res]++;
ans=max(ans,bb[res]);
}
ll ans2=ans;
tr(it,bb){
if(it->se%2==0 && it->fi!=1){
bb[1]+=it->se;
}else{
ans2=max(ans2,it->se);
}
}
ans2=max(ans2,bb[1]);
// debug(aa);
ll q;
cin>>q;
while(q--){
ll x;
cin>>x;
if(x==0){
cout<<ans<<endl;
}else{
cout<<ans2<<endl;
}
}
// cout<<endl;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int32_t main() {
LagaKar;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("Error.txt", "w", stderr);
#endif
primesieve();
ll t; t = 1;
cin >> t;
for (ll i = 1; i <= t; i++) {
chal();
} return 0;
}
1350A - Orac and Factors | 1373A - Donut Shops |
26A - Almost Prime | 1656E - Equal Tree Sums |
1656B - Subtract Operation | 1656A - Good Pairs |
1367A - Short Substrings | 87A - Trains |
664A - Complicated GCD | 1635D - Infinite Set |
1462A - Favorite Sequence | 1445B - Elimination |
1656C - Make Equal With Mod | 567A - Lineland Mail |
1553A - Digits Sum | 1359B - New Theatre Square |
766A - Mahmoud and Longest Uncommon Subsequence | 701B - Cells Not Under Attack |
702A - Maximum Increase | 1656D - K-good |
1426A - Floor Number | 876A - Trip For Meal |
1326B - Maximums | 1635C - Differential Sorting |
961A - Tetris | 1635B - Avoid Local Maximums |
20A - BerOS file system | 1637A - Sorting Parts |
509A - Maximum in Table | 1647C - Madoka and Childish Pranks |