for _ in range(int(input())):
    input()
    A = list(map(int,input().strip().split()))
    B = list(map(int,input().strip().split()))
    vals_a = [0]*(1001)
    for a in A:
        vals_a[a] += 1
        vals_a[a] = min(vals_a[a],1)
    ans = -1
    for b in B:
        if vals_a[b]>0:
            ans = b
            break
    
    if ans == -1:
        print("NO")
    else:
        print("YES")
        print(1,ans)