Automated Budgeting System Balancing equation

Hi, I am creating an automated budgeting system using mainly excel. I did statistics and maths in uni quite some years ago. I am looking for an equation whereby you enter loan amounts "a", "b", and "c". You then enter the amount owing and interest rate for each and the amount of cash available for payment. We'll call these x, y, z. The equation needs to calculate the payment for each loan based on the amount owing and the interest rate on each. I partially remember doing this in statistics but cannot seem to remember or create an equation that does this. Essentialy, I want to use an equation to work out the most efficient way to pay off the loans. Can anyone help?