def solve(n,m,a,b):
    for i in range(n):
        if a[i] in b:return a[i]
    return 'NO'
for _ in range(int(input())):
    n,m=map(int,input().split());a=list(map(int,input().split()));b=list(map(int,input().split()))
    p=solve(n,m,a,b)
    if p=='NO':print(p)
    else:print('YES');print(1,p)
