t = int(input())
for _ in range(t):
    n,m = map(int,input().split())
    a = set(map(int,input().split()))
    b = set(map(int,input().split()))
    c = list(a.intersection(b))
    if len(c) > 0:
        print('YES')
        print(1,c[0])
    else:
        print('NO')