for _ in range(int(input())):
    n,m = map(int,input().split())
    l1 = list(map(int,input().split()))
    l2 = list(map(int, input().split()))
    num = list(set(l1)&set(l2))
    if num:
        print("YES")
        print(1,min(num))
    else:
        print("NO")