for _ in range(int(input())) :
    n, m = map(int, input().split())
    arr = set(map(int, input().split()))
    brr = set(map(int, input().split())) 
    if len(arr.intersection(brr)) >= 1 :
        print("YES")
        print(1, list(arr.intersection(brr))[0])
    else :
        print("NO")