import heapq def dijkstra(n, edges, start): dist = [float('inf')] * n dist[start] = 0 q = [(0, start)] while q: cost, u = heapq.heappop(q) if cost > dist[u]: continue for v, w in edges[u]: if cost + w < dist[v]: dist[v] = cost + w heapq.heappush(q, (dist[v], v)) return dist def solve(): w, e, c = map(int, input().split()) west = [tuple(map(int, input().split())) for _ in range(w-1)] east = [tuple(map(int, input().split())) for _ in range(e-1)] graph = [[] for _ in range(w+e)] for i in range(w-1): u, v = i+1, west[i]-1 graph[u].append((v, 1)) graph[v].append((u, 1)) for i in range(e-1): u, v = i+1+w, east[i]-1 graph[u].append((v, 1)) graph[v].append((u, 1)) # calculate the average distance of the current map dist = [dijkstra(w+e, graph, i) for i in range(w+e)] total = sum(sum(d) for d in dist) count = (w+e) * (w+e-1) avg = total / count res = [] for _ in range(c): u, v = map(int, input().split()) u -= 1 v += w - 1 # recalculate the distance between pairs of stations that include the new station for i in (u, v): dist[i] = dijkstra(w+e, graph, i) for i in range(w+e): for j in range(i+1, w+e): if i == u and j == v or i == v and j == u: continue d = min(dist[i][u] + 1 + dist[v][j], dist[i][v] + 1 + dist[u][j], dist[i][j]) total += d - dist[i][j] dist[i][j] = dist[j][i] = d count = (w+e) * (w+e-1) avg = total / count res.append(avg) print("Case #{}: {}".format(_t+1, " ".join("{:.6f}".format(x) for x in res))) t = int(input()) for _t in range(t): solve()