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] 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): if self.P_sum[i]!=0: 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] if self.P_sum[gx]!=0: self.ans -= self.S_sum[gx]**2 / self.P_sum[gx] if self.P_sum[gy]!=0: self.ans -= self.S_sum[gy]**2 / self.P_sum[gy] self.S_sum[gy] += self.S_sum[gx] if self.P_sum[gx]!=0 and self.P_sum[gy]!=0: self.P_sum[gy] += self.P_sum[gx] elif self.P_sum[gx]==0: self.P_sum[gy] = 0 if self.P_sum[gy]!=0: 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())) 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")