for _ in range(int(input())):
    n, m = map(int, input().split())
    a= list(map(int, input().split()))
    b =list(map(int, input().split()))
    flag = False
    z = 0
    for i in a:
        if(i in b):
            flag = True
            z = i
            break
    if(flag == False):
        print("NO")
    else:
        print("YES")
        print(1, z)