t = int(input())
for _ in range(t):
    n,m = map(int,input().split())
    lst = list(map(int,input().split()))
    lst1 = list(map(int,input().split()))
    dict = {}
    f = True
    for i in lst:
        if i in dict:
            dict[i] += 1
        else:
            dict[i] = 1
    for i in lst1:
        if i in dict:
            print("YES")
            print(1,i)
            f = False
            break
    if f:
        print("NO")
