def solution():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    set_a = set(a)
    for bi in b:
        if bi in set_a:
            print("YES")
            print(f"1 {bi}")
            return
    print("NO")


if __name__ == "__main__":
    t = int(input())
    for _ in range(t):
        solution()
