Two hunters started to walk towards each other simultaneously from two different locations in the forest. The distance between them was 21 miles. The first hunter walked at a rate of 4 mph, while the second one walked at a rate of 3 mph. The first hunter took a dog with him, who ran at an average rate of 5 mph. The dog started to run towards the second hunter, met him and ran back to the first hunter. The dog repeated this until the two hunters met each other. How many miles did the dog run?