SP14971 UOFTAB - The Foxens Treasure
Description
There are $ N $ ( $ 1 \leq N \leq 4 $ ) Foxen guarding a certain valuable treasure, which you'd love to get your hands on. The problem is, the Foxen certainly aren't about to allow that - at least, not while they're awake.
Fortunately, through careful observation, you've seen that each Fox has a regular sleep cycle. In particular, the $ i $ th Fox stays awake for $ A_i $ ( $ 1 \leq A_i \leq 23 $ ) hours, then sleeps for $ S_i $ ( $ 1 \leq S_i \leq 23 $ ) hours, repeating this pattern indefinitely ( $ 2 \leq A_i+S_i \leq 24 $ ). At the start of your treasure-nabbing attempt, the $ i $ th Fox is exactly $ O_i $ ( $ 0 \leq O_i < A_i+S_i $ ) hours into its cycle.
There are $ T $ ( $ 1 \leq T \leq 20 $ ) scenarios as described above. For each one, you'd like to determine how soon all of the Foxen will be simultaneously asleep, allowing you to grab their treasure, or if this will simply never happen.
Input Format
First line: 1 integer, $ T $
For each scenario:
First line: 1 integer, $ N $
Next $ N $ lines: 3 integers, $ A_i $ , $ S_i $ , and $ O_i $ , for $ i = 1..N $
Output Format
For each scenario:
1 integer, the minimum number of hours after the start to wait until all of the Foxen are asleep during the same hour. If this will never happen, output the string "Foxen are too powerful" (without quotes) instead.