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
    j = 0
    for k in range(n-1,-1,-1):
        if f==1:
            break
        else:
            for i in range(m):
                if b[i]==a[k]:
                    f = 1
                    j = a[k]
                    break
    if f==0:
        print('NO')
    else:
        print('YES')
        print(1,j)