t = int(input())
for i in range(t):
    n, m = map(int, input().split())
    a = set(map(int, input().split()))
    b = set(map(int, input().split()))
    if (len(a & b) == 0):
        print('NO')
    else:
        print('YES\n', 1,' ', list(a & b)[0], sep = '')
        