The good news is you get to direct how that payment is applied. You should do so, because if you do fail to direct the application of the payment to a particular debt, the creditor may apply the payment as it chooses to.
There is an exception to these principles, called the “Identical Property” rule. The Identical Property rule provides that when a payment is made and is known by the creditor to have been derived from a particular source, the creditor must apply the payment to that debt associated with that source. A good example is as follows:
It is a good idea to always designate on your payments the account to which that payment should be applied.