for _ in range(int(input())):
    n, m = map(int, input().split())
    a = set(map(int, input().split()))
    b = set(map(int, input().split()))
    val = [0] * 1001
    for x in a:
        val[x] += 1
    for x in b:
        val[x] += 1
    ans = "NO"
    for i in range(1001):
        if val[i] > 1:
            ans = "YES"
            res = i
            break
    print(ans)
    if ans == "YES":
        print(1, res)

