Stepan's Purchases
Ruthenia is a fascinating country with a unique monetary system! They use three types of coins: galleons, sickles, and knuts. One galleon is equivalent to seventeen sickles, and one sickle is equivalent to twenty-nine knuts. All monetary amounts, including prices and cash, are expressed in galleons, sickles, and knuts, where the number of sickles does not exceed 16, and the number of knuts does not exceed 28.
Today is a special day for Stepan as he has received his first scholarship. However, before he can celebrate, he must purchase essential items for his studies, such as a student backpack, an alarm clock, and a pillow.
How much money will Stepan have left after making all these purchases?
Input
The first line contains the amount of money Stepan received, represented by three numbers: the number of galleons, sickles, and knuts, separated by spaces. Remember, the number of sickles does not exceed 16, and the number of knuts does not exceed 28.
The second line contains the number N (0 ≤ N ≤ 100000), which is the number of items that need to be purchased. The following N lines list the prices of each item in the same format as the first line. Each item costs at least one knut.
Data constraints: the number of galleons in each line does not exceed 100,000.
Output
Output a single line indicating the amount of money Stepan has left after all purchases, in the same format as the first line of input. If Stepan does not have enough money, output the number -1.