t = int(input())
while t:
    m, n = [int(x) for x in input().split()]
    a = list(map(int, input().strip().split()))[:m]
    b = list(map(int, input().strip().split()))[:n]
    flag = 0
    for i in range(m):
        if a[i] in b:
            flag = 1
            num = a[i]
            break
    if flag == 0:
        print("NO")
    else:
        print("YES")
        print(1)
        print(num)
    t = t-1
