The first international Geese conference just wrapped up, and even though it should have been a happy occasion, it was bittersweet. The organizers found a paper with detailed plans of a duck infiltration. Now, they are trying to identify the infiltrating group from among the attendees.
The document that they found contained a list of M triples of integers (Xi,Yi,Ci) meaning the ducks would meet exactly Ci seconds after the start of the conference at point (Xi,Yi), which is Xi meters east and Yi meters north of the center of the conference floor. Each goose may or may not have been at those specific points at those specific times, but every duck certainly was.
Both ducks and geese walk at a maximum speed of one meter per second, which means an attendee that is at point (x,y) at time t can reach any point of the form (x+Δx,y+Δy) by time t+Δt as long as Δx2+Δy2≤Δt2. Each attendee's position at time 0 can be any point, independently of the other attendees.
After the discovery, the group held a questioning session to try to identify the ducks. During that session, attendees issued a series of statements, one at a time. The j-th of those, in the order they were issued, was made by attendee Aj, claiming that both they and attendee Bj were at point (Uj,Vj) exactly Dj seconds after the start of the conference. Points in statements may or may not be points where duck meetings happened.
Statements from geese are always true, but ducks may lie. Moreover, ducks know which attendees are ducks and which are geese. To avoid getting caught easily, ducks only make statements that are consistent with all statements previously made by geese. Note that statements made by geese are consistent with all ducks being at all duck meetings.
It may not be possible to determine all the ducks with the information provided. However, knowing the minimum number of ducks will at least provide a lower bound on the level of duck activity. Note that there was at least one duck. Find this minimum number of ducks.
Formally, a hypothesis H is a partition of all attendees into a set of ducks (named H-ducks) and geese (named H-geese). H is consistent with a set of statements S if there exists a path for each attendee moving at most one meter per second such that:
- all H-ducks were at all duck meetings and
- for each statement in S claiming that A saw B at point P at time T, both A and B's paths went through point P at time T.
A hypothesis H is feasible under a set of statements S if:
- H-ducks is not empty (i.e., there was at least one duck),
- the subset of all statements from S made by members of H-geese is consistent with H (i.e., statements from geese are always true), and
- for each statement s∈S made by a member of H-ducks, if P⊆S is the subset of statements made by members of H-geese issued before s, there exists a hypothesis H′ (which may or may not be equal to H) such that {s}∪P is consistent with H′ (i.e., ducks do not contradict previous statements made by geese).
Notice that the hypotheses H such that H-ducks contains all attendees is always feasible.
Find the minimum size of H-ducks over all feasible hypotheses H.
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a line containing three integers, N, M, and S, representing the numbers of attendees, duck meetings, and statements, respectively. The next M lines each describe a different duck meeting with three integers Xi, Yi, and Ci, representing that there was a meeting at point (Xi,Yi), held exactly Ci seconds after the start of the conference. Then, the last S lines of a test case each describe a statement. The j-th of these lines describes the j-th issued statement with five integers Aj, Bj, Uj, Vj, and Dj, representing that attendee Aj stated that they and attendee Bj were both at point (Uj,Vj) exactly Dj seconds after the start of the conference.
Output
For each test case, output one line containing Case #x: y
,
where x is the test case number (starting from 1) and y is the minimum number of ducks
that might have infiltrated the conference.
Limits
Memory limit: 1 GB.
- 1≤T≤50.
- −109≤Xi≤109, for all i.
- −109≤Yi≤109, for all i.
- 1≤Ci≤109, for all i.
- Ci<Ci+1, for all i.
- (Xi−Xi+1)2+(Yi−Yi+1)2≤(Ci−Ci+1)2, for all i.
- 1≤Aj≤N, for all j.
- 1≤Bj≤N, for all j.
- Aj≠Bj, for all j.
- −109≤Uj≤109, for all j.
- −109≤Vj≤109, for all j.
- 1≤Dj≤109, for all j.
- (Aj,Bj,Uj,Vj,Dj)≠(Ak,Bk,Uk,Vk,Dk), for all j≠k.
Test Set 1 (Visible Verdict) (11 points)
Time limit: 20 seconds.
- 2≤N≤50.
- 1≤M≤50.
- 1≤S≤50.
Test Set 2 (Hidden Verdict) (24 points)
Time limit: 60 seconds.
- 2≤N≤105.
- 1≤M≤105.
- 1≤S≤105.
Sample
Input
2
2 1 2
1 2 3
1 2 1 1 1
2 1 2 2 2
4 2 4
4 3 10
-4 -3 20
1 3 4 3 11
2 4 0 0 16
3 1 6 3 9
4 2 0 0 16
Output
Case #1: 1
Case #2: 2
In Sample Case #1, attendee 1 being the only duck is a feasible hypothesis.
In Sample Case #2, attendees 2 and 4 being the only ducks is a feasible hypothesis.
Note that there is at least one duck, so all attendees being geese is not feasible.