for __ in range(int(input())):
    n, m = list(map(int, input().split()))
    ar1 = list(map(int, input().split()))
    ar2 = list(map(int, input().split()))
    x = -1
    ar1 = set(ar1)
    ar2 = set(ar2)
    lol = ar1.intersection(ar2)
    if len(lol) == 0:
        print('NO')
    else:
        print('YES')
        x = 0
        for elem in lol:
            x = elem
        print(1, x)