for _ in range(int(input())):
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    ptd = False
    for i in A:
        if(i in B):
            print("YES")
            print("1",i)
            ptd = True
            break
    if(not ptd):
        print("NO")