for _ in range(int(input())):
    n, m = map(int, input().split())
    li = list(map(int, input().split()))
    li2 = list(map(int, input().split()))
    f = 1
    for i in li:
        if i in li2:
            print("YES")
            print(1, i)
            f = 0
            break
    if(f):print("NO")