class UnionFindVerSize(): def __init__(self, N,init_P,init_S): self._parent = [n for n in range(0, N)] self.P_sum = [0 for i in range(N)] for i in range(N): if init_P[i]: self.P_sum[i] = 1/init_P[i] else: self.P_sum[i] = float("inf") self.S_sum = [init_S[i] for i in range(N)] self._size = [1]*N self.group = N self.ans = 0 for i in range(N): self.ans += (self.S_sum[i]**2)/self.P_sum[i] def find_root(self, x): if self._parent[x] == x: return x self._parent[x] = self.find_root(self._parent[x]) stack = [x] while self._parent[stack[-1]]!=stack[-1]: stack.append(self._parent[stack[-1]]) for v in stack: self._parent[v] = stack[-1] return self._parent[x] def unite(self, x, y): gx = self.find_root(x) gy = self.find_root(y) if gx == gy: return self.group -= 1 if self._size[gx] >= self._size[gy]: gx,gy = gy,gx self._parent[gx] = gy self._size[gy] += self._size[gx] self.ans -= self.S_sum[gx]**2 / self.P_sum[gx] self.ans -= self.S_sum[gy]**2 / self.P_sum[gy] assert self.ans>=0 or abs(ans)<=10**-7 self.S_sum[gy] += self.S_sum[gx] self.P_sum[gy] += self.P_sum[gx] self.ans += self.S_sum[gy]**2 / self.P_sum[gy] def get_size(self, x): return self._size[self.find_root(x)] def is_same_group(self, x, y): return self.find_root(x) == self.find_root(y) import sys input = sys.stdin.readline N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) P = list(map(int,input().split())) #A = [0 for i in range(N)] #A[0] = 1 #B = [0 for i in range(N)] #P = [1 for i in range(N)] S = [A[i]-B[i] for i in range(N)] uf = UnionFindVerSize(N,P,S) ans = [] for _ in range(int(input())): x,y = map(int,input().split()) uf.unite(x-1,y-1) ans.append(uf.ans) print(*ans,sep="\n") #for i in range(len(ans)): #if ans[i] < 10**-7 and ans[i]!=0: #assert False