#include<iostream>
#include<stdio.h>
using namespace std;
#include <set>
#include<vector>
#include<algorithm>
#define ll long long
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include<queue>
#include<map>
#include<stack>
#include<bits/stdc++.h>

const int maxn = 3e5+7;
const ll mod = 1e9+7;
const ll INF=5e18+7;
const int inf=1e9+7;
const ll maxx=1e6+700;

int n;
int a[maxn];
int q;
ll w; 
struct node{
	int x;
	int cnt;
}str[maxn];
map<int,int>mp;

void init(int x){
	for(int i=2;i*i<=x;i++){
		if(x%i==0){
			int cnt1=0;
			while(x%i==0){
				cnt1++;
				x/=i;
			}
			if(cnt1%2) x*=i;
		}
	}
	mp[x]++;
}

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		mp.clear();
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]); 
			init(a[i]);
		}
		int ans1=0,ans2=0;
		map<int,int>::iterator it;
		for(it=mp.begin();it!=mp.end();it++){
			ans1=max(ans1,it->second); 
			if(it->second%2==0||it->first==1){
				ans2+=it->second;
			} 
		}
		ans2=max(ans1,ans2);
		scanf("%d",&q);
		while(q--){
			scanf("%lld",&w);
			if(w==0){
				printf("%d\n",ans1);
			}
			else{
				printf("%d\n",ans2);
			}
		}
	}
}