T = int(input())
while T > 0:
    list_size = [int(x) for x in input().split()]
    
    list1 = [int(x) for x in input().split()]
    list2 = [int(x) for x in input().split()]
    
    
    flag = 0
    for i in list1:
        if i in list2:
            print("YES")
            print(1,i)
            flag = 1
            break
     
    if flag == 0:
        print("NO")
    
    T -= 1