for _ in range(int(input())):
    n, m = map(int, input().split())
    a,b = list(map(int, input().split())),list(map(int,input().split()))
    ans = "NO"
    tmp = 0
    for i in a:
        if i in b:
            ans = "YES"
            tmp = i
            break
    print(ans)
    if ans == "YES":print(1,tmp)