def f (a, b):
    se = set(a)
    for i in b:
        if i in se:
            print("YES")
            print(1, i)
            return
    print("NO")

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