for _ in range(int(input())):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ans = []
    prev = -1
    for i in range(n):
        for j in range(prev+1,m):
            if a[i] == b[j]:
                ans.append(a[i])
                prev = j
                break
    if len(ans)!=0:
        print("YES")
        print("1",ans[0])
    else:
        print("NO")