import sys def calculate_average_distance(W, E, western_connections, eastern_connections, overpass_options): # Initialize the total distance to 0 total_distance = 0 # Iterate through all pairs of western and eastern stations for i in range(W): for j in range(E): # Calculate the distance between the current pair of stations if i == 0: # If the western station is the first station, the distance is the index of the eastern station distance = j elif j == 0: # If the eastern station is the first station, the distance is the index of the western station distance = i else: # Otherwise, the distance is the sum of the index of the western and eastern stations distance = i + j # Add the distance to the total distance total_distance += distance # Calculate the average distance average_distance = total_distance / (W * E) return average_distance # Read the number of test cases T = int(input()) # Iterate through all test cases for t in range(1, T+1): # Read input for the current test case W, E, C = map(int, input().split()) western_connections = list(map(int, input().split())) eastern_connections = list(map(int, input().split())) overpass_options = [] for _ in range(C): overpass_options.append(tuple(map(int, input().split()))) # Calculate the average distance for each overpass option average_distances = [] for option in overpass_options: western_station, eastern_station = option average_distance = calculate_average_distance(W, E, western_connections, eastern_connections, option) average_distances.append(average_distance) # Print the result for the current test case print("Case #{}: {}".format(t, " ".join(map(str, average_distances))))