t = int(input())

for u in range(t):
    n, m = map(int, input().split())
    a = set()
    b = set()

    for i in input().split():
        a.add(int(i))

    for i in input().split():
        b.add(int(i))

    a &= b

    if len(a) == 0:
        print("NO")
    else:
        print("YES")
        for i in a:
            print('1', i)
            break
