t = int(input())
while t:
    t-=1
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a = set(a)
    ans = -1
    for i in b:
        if i in a:
            ans=i
            break
    if ans==-1:
        print('NO')
    else:
        print('YES')
        print(1,ans)
    