#Cooking the Books
Every business can make use of a good accountant and, if they're not big on following the law, sometimes a bad one. Bad accountants try to make more money for their employers by fudging numbers without getting caught.
Sometimes a bad accountant wants to make a number larger, and sometimes smaller. It is widely known that tax auditors will fail to notice two digits being swapped in any given number, but any discrepancy more egregious will certainly be caught. It's also painfully obvious when a number has fewer digits than it ought to, so a bad accountant will never swap the first digit of a number with a 0.
Given a number, how small or large can it be made without being found out?
#New Year's Resolution
Alex's New Year's resolution for 2015 is to eat healthier foods. He's done some research and has found out that calories come from three main sources, called macronutrients: protein, carbohydrates, and fat. Alex wants to get the right balance of protein, carbohydrates, and fat to have a balanced diet. For each available food, Alex can only choose to eat it or not eat it. He can't eat a certain food more than once, and he can't eat a fractional amount of a food.
Input begins with an integer T, the number of test cases. For each test case, the first line consists of three space-separated integers: GP, GC, and GF, which represent the amount of protein, carbohydrates, and fat that Alex wants to eat. The next line has the number of foods for that test case, an integer N. The next N lines each consist of three space-separated integers: P, C, and F, which represent the amount of protein, carbohydrates, and fat in that food, respectively.