Ответ:

  1. Before the competition began, they had been packing. Длительное действие продолжалось до другого события в прошлом.
  2. My head hurt because I had been listening to music for three hours. Указана длительность действия.
  3. He had missed his bus, so he was really late. Пропуск автобуса произошёл раньше опоздания.
  4. When I opened the cupboard, I saw that someone had already taken the mugs. Действие завершилось до того, как я открыл шкаф.
  5. He had been working since early morning when we finally reached him. Действие длилось с раннего утра.
  6. He got lost because he had not taken a map. Отсутствие карты предшествовало тому, что он заблудился.
  7. By the time we reached the canyon, it had stopped raining. Дождь прекратился до нашего прибытия.
  8. I was tired because I had been walking for three hours. Указана длительность ходьбы.
  9. When Alice finally arrived at the party, everybody had gone home. Все ушли до её приезда.