def average_distance(w, e, x, f): # calculate average distance for western side dist_west = [0] * w for i in range(1, w): if x[i-1] == i: dist_west[i] = dist_west[i-1] else: dist_west[i] = dist_west[i-1] + 1 avg_west = sum(dist_west) / (w * (w-1) / 2) # calculate average distance for eastern side dist_east = [0] * e for i in range(1, e): if f[i-1] == i: dist_east[i] = dist_east[i-1] else: dist_east[i] = dist_east[i-1] + 1 avg_east = sum(dist_east) / (e * (e-1) / 2) # calculate new average distances for each option options = [] for i in range(c): a, b = map(int, input().split()) a -= 1 b -= 1 len_ab = dist_west[a] + dist_east[b] + 1 new_avg = (w * e - 1 + len_ab) / (w * e) options.append(new_avg) return options t = int(input()) for case in range(1, t+1): w, e, c = map(int, input().split()) x = list(map(int, input().split())) f = list(map(int, input().split())) options = average_distance(w, e, x, f) print(f"Case #{case}: {' '.join(f'{o:.6f}' for o in options)}")