t = int(input())
for _ in range(t):
    n, m = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    res = None
    x = 0
    for i in a:
        if i in b :
            res = i
            x+=1
            print('YES')
            print(1, i)
            break
    if(x==0):
        print('NO')