def solve():
    # put code here
    n,m=[int(v) for v in input().split()]
    arr={int(v) for v in input().split()}
    brr={int(v) for v in input().split()}
    crr= arr & brr
    if crr:
        print('YES')
        print(1, crr.pop())
    else:
        print('NO')

t = int(input())
for _ in range(t):
    solve()
