for _ in range(int(input())):
    n, m = list(map(int, input().split()))

    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a = set(a)
    b = set(b)
    
    check = True
    
    for i, v in enumerate(a):
        if v in b:
            check = True
            r = v
            break
        else:
            check = False
        
    
    if check:
        print("YES")
        print(1, r)
    else:
        print("NO")


