for _ in range(int(input())):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    f = 0
    for i in a:
        if i in b:
            f=1
            break
    if f==1:
        print('YES')
        print(1,i)
    else:
        print('NO')