t = int(input())

for i in range(0, t):
    n,m = map(int, input().split())
    arr1 = list(map(int, input().split()))
    arr2 = list(map(int, input().split()))
    common = -1
    for i in arr1:
        if i in arr2:
            common = i
            break
    if common > -1: 
        print("YES", end="\n")
        print(1, common)
    else: print("NO")