def solve_case(case_num, N, M, Q, bus_routes, contests): # Initialize the graph graph = [[] for _ in range(N + 1)] for u, v, k in bus_routes: graph[u].append((v, k)) graph[v].append((u, k)) # DFS to count the number of routes with each club club_counts = [0] * 101 visited = [False] * (N + 1) def dfs(node, club_count): visited[node] = True club_counts[club_count] += 1 for neighbor, neighbor_club in graph[node]: if not visited[neighbor]: dfs(neighbor, club_count ^ neighbor_club) # Process each contest odd_count = 0 for p, c in contests: # Count the number of routes with each club from p to c club_counts = [0] * 101 visited = [False] * (N + 1) dfs(p, 0) if club_counts[0] > 0: club_counts[0] -= 1 for club_count in club_counts: if club_count % 2 == 1: odd_count += 1 break # Output the result for this test case print("Case #{}: {}".format(case_num, odd_count-1)) # Read the input T = int(input()) for case_num in range(1, T + 1): N, M, Q = map(int, input().split()) bus_routes = [tuple(map(int, input().split())) for _ in range(M)] contests = [tuple(map(int, input().split())) for _ in range(Q)] solve_case(case_num, N, M, Q, bus_routes, contests)