t = int(input())
for case in range(t):
    n, m = map(int, input().split())
    a = input().split()
    b = input().split()
    yes = False
    for i in range(n):
        if a[i] in b:
            yes = True
            print("YES")
            print("1 " + a[i])
            break
    if yes == False:
        print("NO")