for _ in range(int(input())):
    n,m=map(int,input().split())
    arr1 = list(map(int,input().split()))
    arr2 = list(map(int,input().split()))
    for i in arr1:
        if(i in arr2):
            print("YES")
            print(1,i)
            break
    else:
        print("NO")