for _ in range(int(input())):
    n,m = map(int,input().split())

    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    dic = {}

    for i in a:dic[i]=1

    flag = False
    n = 0
    for i in b:
        if i in dic:
            n = i
            flag = True
            break
    if flag==False:
        print('NO')
    else:
        print('YES')
        print(1,n)