Your character in an RPG game has G1 gold, S1 silver and B1 bronze coins. You need G2 gold, S2 silver and B2 bronze coins to buy a new armor. A bank in the game supports four types of exchange operations:
1. the bank will give you 9 silver coins in exchange for 1 gold coin
2. the bank will give you 1 gold coin in exchange for 11 silver coins
3. the bank will give you 9 bronze coins in exchange for 1 silver coin
4. the bank will give you 1 silver coin in exchange for 11 bronze coins
Return the minimal number of exchange operations required for your character to hold at least G2 gold, at least S2 silver and at least B2 bronze coins. Return -1 if the character does not have enough money for that.
- G1, S1, B1, G2, S2 and B2 will each be between 0 and 1,000,000, inclusive.
Line1 - No of test cases T (<50)
Next T Lines contain values of G1, S1, B1, G2, S2 and B2 separated by spaces.
Line 1 to T - Each line contain Required Number for the corresponding test case.
1 0 0 0 0
Initially, you have one gold coin. You should exchange it for 9 silver coins. After that you should exchange each of the 9 silver coins for 9 bronze coins.