for _ in range(int(input())):
    n, m = map(int, input().split())
    arr_n = list(map(int, input().split()))
    arr_m = list(map(int, input().split()))
    flag = False
    ans = 0
    for i in range(n):
        for j in range(m):
            if arr_n[i]==arr_m[j]:
                flag = True
                ans = arr_n[i]
                break
        if flag == True:
            break
    if flag == True:
        print("YES")
        print(1,ans)
    else:
        print("NO")