for T in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ok = 0
    ans = 0
    for x in a:
        for y in b:
            if x == y:
                ok = 1
                ans = x
    if ok:
        print('YES')
        print(1, ans)
    else:
        print('NO')
