t = int(input())
for abc in range(t):
    f = True
    n, m = map(int, input().split())
    a = set(map(int, input().split()))
    b = set(map(int, input().split()))
    for i in a:
        if i in b:
            print('YES')
            print(1, i)
            f = False
            break
    if f:
        print('NO')