import sys

v = int(input())

while(v > 0):
    
    n, m = map(int, sys.stdin.readline().split())

    f = False

    h1 = set(map(int, sys.stdin.readline().split()))
    arr = list(map(int, sys.stdin.readline().split()))
    
    
    for x in h1:
        if(x in arr):
            print("YES")
            print("1" + " " + str(x))
            f=True
            break;
    
    
    if(f == False): print("NO")
    v = v -1