t = int(input())
pi = 3.1415
# t = 1
for _ in range(t):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    dict = {}
    for i in range(len(a)):
        dict[a[i]] = 1
    tag = 0
    for i in range(len(b)):
        if (b[i] in dict.keys()):
            print("YES")
            print(1, b[i])
            tag = 1
            break
    if (tag == 0):
        print("NO")
