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