for _ in range(int(input())):
    n,m = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    for i in a:
        if i in b:
            print("YES")
            print('1',i)
            break
        else:
            continue
    else:
        print("NO")
