t = int(input())
for _ in range(0,t):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    ok = False
    for i in range(0,n):
        if b.count(a[i]) != 0:
            print('YES')
            print(1,a[i])
            ok = True
            break

    if not ok:
        print('NO')
