t = int(input().split()[0])
for case in range(t):
    n,m = map(int,input().split())
    a = set(map(int,input().split()))
    b = list(map(int,input().split()))
    flag = False
    for i in range(m):
        if b[i] in a:
            print("YES")
            print("1 " + str(b[i]))
            flag = True
            break
    if flag == False:
        print("NO")
