for i in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = []
    if(n < m):
        for i in range(n):
            if a[i] in b:
                c.append(a[i])
                break
    else:
        for i in range(m):
            if b[i] in a:
                c.append(b[i])
                break
    if(len(c) == 0):
        print("NO")
    else:
        print("YES")
        print(1, c[0])
    
    