Working together on tasks builds trust, problem-solving abilities, and a sense of belonging—key foundations for lasting friendships.