for _ in range(int(input())):
    n,m = map(int,input().split())
    a_list = list(map(int,input().split()))
    b_list = list(map(int,input().split()))
    ans = []
    for u in a_list:
        if u in b_list:
            ans.append(u)
            break
    if ans:
        print('YES')
        print(len(ans),*ans)
    else:
        print('NO')