def main():
    n, m = map(int, input().split())
    arr_n = list(map(int, input().split()))
    arr_m = list(map(int, input().split()))
    for i in arr_n:
        if i in arr_m:
            print("YES")
            print("1 {}".format(i))
            return
    print("NO")


for _ in range(int(input())):
    main()
