t = int(input())
res = []

for i in range(t):
    n,m = list(map(int, input().split()))
    arr1 = list(map(int, input().split()))
    arr2 = list(map(int, input().split()))
    commonArr = list(set(arr1).intersection(set(arr2)))
    if len(commonArr) == 0:
        res += [["NO"]]
    else:
        res += [["YES"], ["1 " + str(commonArr[0])]]
for i in res:
    for j in i:
        print(j)