t = int(input())
for _ in range(t):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    a = set(a)
    b = set(b)
    d = dict()
    ans = -1
    for i in a:
        if i not in d.keys():d[i]=1
    for j in b:
        if j not in d.keys():d[j]=1
        else:
            ans = j
            break
    if ans == -1:print('NO')
    else:
        print("YES")
        print(1,ans)
