#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(), x.end()
#define REP(i,a,b) for(int i = a; i < b; ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;


void solve(){
	int n; cin >> n;
    unordered_map<int,int> hcnt;
    REP(i,0,n) {
        int num; cin >> num;
        int h = 1;
        for(int p = 2; p * p <= num; ++p) {
            int cnt = 0;
            while(num % p == 0) {
                ++cnt;
                num /= p;
            }
            if(cnt % 2 == 1) h *= p;
        }
        if(num > 1) h *= num;
        if(hcnt.count(h)) ++hcnt[h];
        else hcnt[h] = 1;
    }
    int a = 0, b = 0;
    for(auto& hc : hcnt) {
        if(hc.first == 1 || hc.second % 2 == 0) b += hc.second;
        a = max(a, hc.second);
    }
    int q; cin >> q;
    while(q--) {
        ll w; cin >> w;
        if(w == 0) cout << a << endl;
        else cout << max(a,b) << endl;
    }
    
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t; cin >> t;
    while(t--) solve(); 
}
