def calculate_sum_of_lengths(N, connections): sum_lengths = 0 for i in range(N - 1): sum_lengths += (i + 1) * (N - connections[i]) return sum_lengths T = int(input()) for t in range(T): W, E, C = map(int, input().split()) west_connections = list(map(int, input().split())) east_connections = list(map(int, input().split())) sum_west = calculate_sum_of_lengths(W, west_connections) sum_east = calculate_sum_of_lengths(E, east_connections) avg_distances = [] for _ in range(C): A, B = map(int, input().split()) total_sum = sum_west + sum_east + A * B avg_distance = total_sum / ((W + E) * (W + E - 1) // 2) avg_distances.append(avg_distance) print(f"Case #{t+1}: {' '.join(map(str, avg_distances))}")