for _ in range(int(input())):
    [n,m] = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a = set(a)
    b = set(b)
    if (a&b):
        print("YES")
        print(*[1, list(a&b)[0]])
    else:
        print("NO")