def solve():
    n,m=map(int,input().split())
    *a,=map(int, input().split())
    *b,=map(int, input().split())
    
    sa=set(a);sb=set(b)
    if sa&sb:
        print("YES")
        for c in sa&sb:
            print(1,c)
            break
    else:
        print("NO")
    
t =int(input())
for _ in range(t):
    solve()