from sys import stdin
 
for case in range(int(stdin.readline())):
    n,m = [int(x) for x in stdin.readline().split()]
    
    n = set([int(x) for x in stdin.readline().split()])
    m = set([int(x) for x in stdin.readline().split()])
    
    bruh = n.intersection(m)
    
    if bruh:
        for x in bruh:
            print("YES")
            print(1, x)
            break
    else:
        print('NO')