def solve(arr1,arr2,ans):
    for i in arr1:
        if i in arr2:
            ans.append('YES')
            ans.append('1 '+str(i))
            return

    ans.append('NO')

def main():
    t = int(input())
    ans = []
    for i in range(t):
        n,m = map(int,input().split())
        arr1 = set(map(int,input().split()))
        arr2 = set(map(int,input().split()))
        solve(arr1,arr2,ans)

    for i in ans:
        print(i)
    
main()
