#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int u[N], v[N], w[N], son[N];
double p[N];
vector<int> g[N];
void dfs(int u, int fa) {
  son[u] = 1;
  for (int i = 0, vv; i < g[u].size(); ++i) {
    vv = g[u][i];
    if (vv == fa) continue;
    dfs(vv, u);
    son[u] += son[vv];
  }
}
int main() {
  int n, q;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d%d", &u[i], &v[i], &w[i]);
    g[u[i]].push_back(v[i]);
    g[v[i]].push_back(u[i]);
  }
  dfs(1, -1);
  double ans = 0.0;
  for (int i = 1; i < n; ++i) {
    int tx = son[u[i]], ty = son[v[i]];
    if (tx < ty) swap(tx, ty);
    long long t1 = (long long)ty * (ty - 1) * (n - ty) +
                   (long long)(n - ty) * (n - ty - 1) * ty;
    t1 *= 6;
    long long t2 = (long long)n * (n - 1) * (n - 2);
    p[i] = 1.0 * t1 / t2;
    ans += p[i] * w[i];
  }
  scanf("%d", &q);
  while (q--) {
    int x;
    long long y;
    scanf("%d%I64d", &x, &y);
    ans -= p[x] * w[x];
    ans += p[x] * y;
    w[x] = y;
    printf("%.10lf\n", ans);
  }
  return 0;
}
