for _ in range(int(input())):
    z = 0
    [x,y]=list(map(int,input().split()))
    l1 = list(map(int,input().split()))
    l2 = list(map(int,input().split()))
    for i in range(len(l1)):
        if l1[i] in l2:
            z = 1
            print("YES")
            print(1,l1[i])
            break
    if z==0:
        print("NO")