#include using namespace std; int par[100001], sz[100001]; int freq[100001][11][11]; long long X[100001]; double val[100001]; double ans; int find(int x) { if(x == par[x]) return x; return par[x] = find(par[x]); } void merge(int x, int y) { if(find(x) == find(y)) return; x = find(x), y = find(y); if(sz[x] < sz[y]) swap(x, y); X[x] += X[y]; par[y] = x; sz[x] += sz[y]; ans -= val[x]; ans -= val[y]; double num = X[x], den = 0.0; for(int i = 0; i <= 10; i++) { for(int j = 0; j <= 10; j++) { freq[x][i][j] += freq[y][i][j]; num -= freq[x][i][j] * j; if(i) den += freq[x][i][j] * 1.0 / i; } } ans += num * 1.0 * num / den; val[x] = num * 1.0 * num / den; } int main() { int N; cin >> N; vector A(N), B(N), P(N); for(int i = 0; i < N; i++) { cin >> A[i]; } for(int i = 0; i < N; i++) { cin >> B[i]; } for(int i = 0; i < N; i++) { cin >> P[i]; } iota(par, par + N, 0); memset(sz, 1, sizeof(sz)); for(int i = 0; i < N; i++) { X[i] = A[i]; val[i] = P[i] * (A[i] - B[i]) * (A[i] - B[i]); freq[i][P[i]][B[i]] = 1; ans += val[i]; } cout << setprecision(24); int Q; cin >> Q; while(Q--) { int X, Y; cin >> X >> Y; --X, --Y; merge(X, Y); cout << ans << "\n"; } }