t = int(input())

for _ in range(t):

    n,m = map(int,input().split())

    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    b.sort()
    setA = set(a)
    flag = 0

    for i in b:
        if i in setA:
            flag = 1
            print('YES')
            print(1,i)
            break

    if flag == 0:
        print('NO')
    
