#yuki-1365 from collections import defaultdict N = int(input()) A = list(map(int, input().split())) #初期エネルギー B = list(map(int, input().split())) #目標エネルギー P = list(map(int, input().split())) #重みづけ P2 = [float('inf') if p == 0 else 1/p for p in P] class UnionFind(): def __init__(self, n): self.n = n self.roots = [[-1, A[i], B[i], P2[i]] for i in range(n)] def find(self, x): #xの根を見つける if self.roots[x][0] < 0: return x else: self.roots[x][0] = self.find(self.roots[x][0]) #つなぎ直す return self.roots[x][0] def union(self, x, y): #x,yが入っている部分集合を合体させる x = self.find(x) y = self.find(y) if x == y: return if self.roots[x][0] > self.roots[y][0]: x, y = y, x for i in range(4): self.roots[x][i] += self.roots[y][i] self.roots[y][0] = x # def size(self, x): #ある元が入っている部分集合の大きさを求める return -self.roots[self.find(x)][0] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def rootss(self): return [i for i, x in enumerate(self.roots) if x[0] < 0] def group_count(self): return len(self.rootss()) def all_group_members(self): #defaultdictの形で各部分集合を返す group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) def cost(self): c = 0 for r in self.rootss(): a, b, p2 = self.roots[r][1:] c += (a-b)**2/p2 return c u = UnionFind(N) Q = int(input()) ans = sum(P[i]*(A[i]-B[i])**2 for i in range(N)) for _ in range(Q): X, Y = map(int, input().split()) u.union(X-1, Y-1) print(u.cost())