Two cars P and Q start from two points A and B towards each other simultaneously. They meet for the first time $40$ km from B. After meeting they exchange their speeds as well as directions and proceed to their respective starting points. On reaching their starting points, they turn back with the same speeds and meet at a point $20$ km from A. Find the distance between A and B.