for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    ans=0
    for x in range(n):
        for y in range(m):
            if a[x]==b[y]:
                ans=a[x]
                break
        if ans!=0:
            break
    if ans!=0:
        print('YES')
        print(1, end=' ')
        print(ans)
    else:
        print('NO')
