t = int(input())
for i in range(t):
    n,m = map(int,input().split())
    ai  = list(map(int,input().split()))
    bi  = list(map(int,input().split()))
    ai2 = [0] * 1001
    num = 0
    for i in range(n):
        ai2[ai[i]] = 1
    for i in range(m):
        if ai2[bi[i]] == 1:
            num = bi[i]
            break
    if num != 0:
        print("YES")
        print(1,num)
    else:
        print("NO")
