'''import sys
input=lambda:sys.stdin.readline().strip()
t=int(input())
for i in range(t):
    n,q=map(int,input().split())
    zhonglei=list(map(int,input().split()))
    days=list(map(int,input().split()))
    p=[0]*(n+3)
    dict={}
    for coun in range(0,n+1):
        c=zhonglei.count(coun)
        dict[coun]=c
    c=max(zhonglei)
    counts ={}
    for value in dict.values():
        if value in counts:
            counts[value]+=1
        else:
            counts[value]=1
    for d in range(c+1):
        p[0]=n
        if d in counts:
            p[d+1] = (p[d] - (counts[d] * d))
    
    for j in days:
        if j<c:
            print(p[j+1],end=' ')
        else:
            print(0,end=' ')
            
'''
import sys
from collections import Counter

input = lambda: sys.stdin.readline().strip()

t = int(input())
for _ in range(t):
    n, q = map(int, input().split())
    zhonglei = list(map(int, input().split()))
    days = list(map(int, input().split()))
    
    # 1. 统计每种果子出现的次数
    type_count = Counter(zhonglei)  # 正确:统计每种果子的数量
    
    # 2. 统计freq:有k个果子的种类,总共有多少个果子
    freq = {}
    for cnt in type_count.values():
        freq[cnt] = freq.get(cnt, 0) + cnt#没创建key会返回0
    
    # 3. 找到最大数量
    if freq:
        max_cnt = max(freq.keys())
    else:
        max_cnt = 0
    
    # 4. 计算前缀和
    prefix = [0] * (max_cnt + 2)
    prefix[0] = 0
    for d in range(1, max_cnt + 1):
        prefix[d] = prefix[d-1] + freq.get(d, 0)
    
    # 5. 回答每个询问
    total = n
    answers = []
    for d in days:
        if d > max_cnt:
            removed = prefix[max_cnt]
        else:
            removed = prefix[d]
        answers.append(str(total - removed))
    
    print(" ".join(answers))