def solve_case(w, e, c, west, east, options): graph = [[float('inf')] * (w + e) for _ in range(w + e)] for i in range(w - 1): graph[i][i + 1] = graph[i + 1][i] = 1 for i in range(e - 1): graph[w + i][w + i + 1] = graph[w + i + 1][w + i] = 1 for a, b in options: graph[a - 1][w + b - 1] = graph[w + b - 1][a - 1] = 1 for k in range(w + e): for i in range(w + e): for j in range(w + e): graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]) sum_dist = 0 num_pairs = w * e for i in range(w): for j in range(e): dist = graph[i][w + j] sum_dist += dist avg_dist = sum_dist / num_pairs return avg_dist t = int(input()) for i in range(t): w, e, c = map(int, input().split()) west = list(map(int, input().split())) east = list(map(int, input().split())) options = [list(map(int, input().split())) for _ in range(c)] ans = solve_case(w, e, c, west, east, options) print("Case #{}: {}".format(i + 1, " ".join("{:.6f}".format(x) for x in ans)))