# import pypyjit # pypyjit.set_param("max_unroll_recursion=-1") from collections import * from functools import * from itertools import * from heapq import * import sys, math # sys.setrecursionlimit(10**4) input = sys.stdin.readline class DSU: def __init__(self, n , B, P, A): self._n = n self.parent_or_size = [-1] * n self.P = P self.B = B self.SE = A self.SPB = [p*b*b for p,b in zip(P,B)] self.SB = B self.IP = [1/(p+0.000000000000001) for p in P] def merge(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n x, y = self.leader(a), self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.SB[x] += self.SB[y] self.SPB[x] += self.SPB[y] self.SE[x] += self.SE[y] self.IP[x] += self.IP[y] self.parent_or_size[y] = x return x def same(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a): assert 0 <= a < self._n if self.parent_or_size[a] < 0: return a self.parent_or_size[a] = self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self, a): assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf = [self.leader(i) for i in range(self._n)] result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return [r for r in result if r != []] N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) P = list(map(int,input().split())) D = DSU(N,B,P,A) Q = int(input()) ans = sum(p*(e-b)**2 for p,e,b in zip(P,A,B)) for _ in range(Q): x,y = map(int,input().split()) x -= 1 y -= 1 lx = D.leader(x) ly = D.leader(y) if D.same(x,y): print(ans) continue else: bef = (-D.SPB[lx] + (D.SE[lx] - D.SB[lx])**2/D.IP[lx] -D.SPB[ly] + (D.SE[ly] - D.SB[ly])**2/D.IP[ly] ) D.merge(x,y) lx = D.leader(x) aft = -D.SPB[lx] + (D.SE[lx] - D.SB[lx])**2/D.IP[lx] ans += aft-bef print(ans) # print(D.SB)