## B: The Foxen's Treasure

There are N (1 ≤ N ≤ 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 ith Fox stays awake for Ai (1 ≤ Ai ≤ 23) hours, then sleeps for Si (1 ≤ Si ≤ 23) hours, repeating this pattern indefinitely (2 ≤ Ai + Si ≤ 24). At the start of your treasure-nabbing attempt, the ith Fox is exactly Oi (0 ≤ Oi < Ai + Si) hours into its cycle.

There are T (1 ≤ T ≤ 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

Line 1: 1 integer, T
For each scenario:
Line 1: 1 integer, N
Next N lines: 3 integers, Ai, Si, and Oi, for i = 1..N

### Output

For each scenario:
Line 1: 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.

### Sample Input

2
2
2 1 2
2 2 1
3
1 1 0
1 1 0
1 1 1

### Sample Output

6
Foxen are too powerful

### Explanation of Sample

In scenario 1, the following table illustrates the Foxen's sleeping cycles (with A representing being awake, S representing sleep, and a bold letter representing the start of a sleep cycle):

HourFox 1Fox 2
0SA
1AS
2AS
3SA
4AA
5AS
6SS

As can be seen, the first hour during which both Foxen are asleep is 6 hours after the start.

In scenario 2, the first 2 Foxen are always awake and asleep at the same times. However, the third Fox's schedule is exactly flipped, which means that it will never be asleep at the same time as the others.

Point Value: 7
Time Limit: 10.00s
Memory Limit: 64M
Added: Oct 02, 2012
Author: SourSpinach

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

## Comments (Search)

• (0/0)
My error message is the following:
Your Output (clipped)
6
Foxen are too powe

My code completes the word powerful and this would make the output identical to that in the example. What is wrong? Are there other test cases that it goes through??

• (0/0)
The output is clipped, meaning that we cut it off and only show some of it. There are indeed other cases that you are failing.

• (0/0)
I passed it and saw other different submission; they test up to a given number (I didn't need it, using a Python while loop with the break command once a certain condition was met), but I wonder where that number comes from: any hint?

If needed and allowed, I could post the specific number, but, in doubt, I prefer to omit it; my submission used a random larger number.

• (0/0)
help please!
I'm getting a weird error message saying that its "clipped"
here it is:

Test case #1: RE (signal 6: SIGABRT) [0.003s, 1924K] (0/1) (Details)
Your Output
Standard Error (clipped)
a.out: malloc.c:3096

Final score: 0/1

• (1/0)
(clipped) just means that isn't the full error message. If it doesn't make sense to you, just ignore it.
Go back and try to figure out why your code might have a runtime error.

• (0/0)
The runtime error your program produces just isn't displayed fully. Something's going wrong with your malloc, you can just initialize things statically instead. Also, note that you can always produce output for each test case after it's been read, as opposed to after you've finished inputting everything.

• (0/0)
There is a missing newline between the "01" in the given sample input.

• (0/0)
Fixed