Let us call two integers x and y adjacent if (lcm(x, y))/(gcd(x, y)) is a perfect square. For example, 3 and 12 are adjacent, but 6 and 9 are not.

Here gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y, and lcm(x, y) denotes the [least common multiple (LCM)](https://en.wikipedia.org/wiki/Least_common_multiple) of integers x and y.

You are given an array a of length n. Each second the following happens: each element a_i of the array is replaced by the product of all elements of the array (including itself), that are adjacent to the current value. 

Let d_i be the number of adjacent elements to a_i (including a_i itself). The beauty of the array is defined as max_{1 ≤ i ≤ n} d_i. 

You are given q queries: each query is described by an integer w, and you have to output the beauty of the array after w seconds.

Input

The first input line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.

The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5) — the length of the array.

The following line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10^6) — array elements. 

The next line contain a single integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries.

The following q lines contain a single integer w each (0 ≤ w ≤ 10^{18}) — the queries themselves.

It is guaranteed that the sum of values n over all test cases does not exceed 3 ⋅ 10^5, and the sum of values q over all test cases does not exceed 3 ⋅ 10^5

Output

For each query output a single integer — the beauty of the array at the corresponding moment.

Example

Input


2
4
6 8 4 2
1
0
6
12 3 20 5 80 1
1
1


Output


2
3

Note

In the first test case, the initial array contains elements [6, 8, 4, 2]. Element a_4=2 in this array is adjacent to a_4=2 (since (lcm(2, 2))/(gcd(2, 2))=2/2=1=1^2) and a_2=8 (since (lcm(8,2))/(gcd(8, 2))=8/2=4=2^2). Hence, d_4=2, and this is the maximal possible value d_i in this array.

In the second test case, the initial array contains elements [12, 3, 20, 5, 80, 1]. The elements adjacent to 12 are \{12, 3\}, the elements adjacent to 3 are \{12, 3\}, the elements adjacent to 20 are \{20, 5, 80\}, the elements adjacent to 5 are \{20, 5, 80\}, the elements adjacent to 80 are \{20, 5, 80\}, the elements adjacent to 1 are \{1\}. After one second, the array is transformed into [36, 36, 8000, 8000, 8000, 1].
"""
#If FastIO not needed, use this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""

import os
import sys
from io import BytesIO, IOBase
import heapq as h 
from bisect import bisect_left, bisect_right
import time

from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string

start_time = time.time()

def getInts():
    return [int(s) for s in input().split()]

def getInt():
    return int(input())

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

def getMat(n):
    return [getInts() for _ in range(n)]

def isInt(s):
    return '0' <= s[0] <= '9'

MOD = 10**9 + 7 

"""
Element replaced by product of elements adjacent to itself
LCM/GCD a perfect square
Number 1 = GCD * sq1
Number 2 = GCD * sq2

sq1 and sq2 are coprime

Obs 1: Adjacent elements for disjoint sets
Obs 2: The number of disjoint sets gets smaller
Obs 3: if in a given move, the number of disjoint sets is the same as in the previous move, it will be this way forever
Obs 4: This can only take at most N moves

Adjacency classes are defined by the prime factors with ODD

If you multiply an adjacency class by itself an odd number of times, it remains the same
If you multiply it by itself an even number of times, it becomes 1
After 1 second, all the even sized classes have become 1
After 2 seconds, all classes have become 1
"""


squares = []
for i in range(1,1001):
    squares.append(i*i)

adj_class = [0]*(10**6+1)
curr = 0
for i in range(1,10**6+1):
    if not adj_class[i]:
        curr += 1
        for sq in squares:
            if sq*i > 10**6: break
            adj_class[sq*i] = curr

#print(adj_class[:50])

def solve():
    N = getInt()
    A = getInts()
    max_val = 0
    counts = dd(int)
    for a in A:
        counts[adj_class[a]]+=1
    max_odds = 0
    total_evens = 0
    max_val = 0
    #print(counts[:10])
    for key, x in counts.items():
        if x % 2 == 1 and key > 1:
            max_odds = max(max_odds,x)
        else:
            total_evens += x
        max_val = max(max_val,x)
    q = getInt()
    for _ in range(q):
        x = getInt()
        if x >= 1:
            print(max(total_evens,max_odds))
        else:
            print(max_val)
    return
            
for _ in range(getInt()):
    #print(solve())
    solve()
    


#print(time.time()-start_time)