Problems
After Apricot Rules LLC went through a reorganization, a new large team was formed containing
The introduction sessions are organized into time slots that take
For some pairs of people in the team, we want to know the shortest time
that is needed for them to finally know each other, or whether it is
impossible for that to happen through the described process. If two people know each
other before any introduction sessions happen, we define that shortest
time to be
Even though we are interested in multiple pairs of people, we are considering the situations independently. That is, the minimum time for each pair can depend on a specific organization of the introduction that is particular to that pair only.
Input
The first line of the input gives the number of test cases, Y if team members N otherwise. Then, there are
Output
For each test case, output one line containing
Case #,
where
Example #1
3
2 2 3
YYYY
YYNN
YNYN
YNNY
2 3
2 4
1 4
3 2 2
YYYNN
YYNYN
YNYNY
NYNYN
NNYNY
2 5
4 5
1 1 1
YN
NY
1 2
Case #1: 1 1 0
Case #2: 2 3
Case #3: -1
Example #2
1
5 1 1
YYNNNN
YYYNNN
NYYYNN
NNYYYN
NNNYYY
NNNNYY
1 6
Case #1: 3