t = int(input())

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

    ans = []
    for number in a:
        if number in b:
            ans = number
            break

    if ans:
        print('YES')
        print(1, ans)
    else:
        print("NO")
