for i in range(int(input())):
    n, m = map(int, input().split(" "))
    l1 = list(map(int, input().split(" ")))
    l2 = list(map(int, input().split(" ")))
    r = "NO"
    ans = -1
    for i in range(n):
        if l1[i] in l2:
            r = "YES"
            ans = l1[i]
            break
    if r =="YES":
        print(r)
        print(1, ans)
    else:
        print("NO")
