for _ in range(int(input())):
    n,k = map(int,(input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ans = True
    for i in a:
        if i in set(b):
            print('YES')
            print(1,i)
            ans = False
            break
    if ans:
        print('NO')
            
        
