t = int(input())

for _ in range(t):
    n,m = map(int,input().split())
    a =list(map(int,input().split()))
    b = list(map(int,input().split()))
    cnt = {}
    flag = 0
    for i in a:
        cnt[i] = 0
    for i in b:
        cnt[i] = 0
    for i in a:
        cnt[i] = 1
    for i in b:
        if cnt[i] == 1:
            flag = i
            break
    if flag:
        print("YES")
        print(1,flag)
    else:
        print("NO")