t = int(input())
for testcase in range(t):
    n,m=map(int,input().split())
    
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    T = True
    for i in range(n):
        if a[i] in b:
            print('YES')
            print(1,a[i])
            T=True
            break

        else:
            T=False
    if(T==False):
        print('NO')            
        
            

    
        



