You basically have to remember three things:
1. You enter and leave a country on the same passport.
2. The passport you use to enter a country at the end of a flight does not have to be the same one that you used to leave a different country at the start of that flight.
3. Airline people know this.