#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, no;
} t;
int n, num[100005], i, u, v, q, x;
double w[100005], Cn3, ans, y;
vector<Edge> g[100005];
int dfs(int now, int from) {
  int tot = 0;
  for (int i = 0; i < g[now].size(); ++i) {
    int v = g[now][i].to, id = g[now][i].no;
    if (v == from) continue;
    num[id] = dfs(v, now);
    tot += num[id];
  }
  return tot + 1;
}
double count(int x) {
  double a = num[x], b = double(n) - num[x];
  return 2.0 * w[x] / Cn3 * (a * (a - 1) / 2.0 * b + b * (b - 1) / 2.0 * a);
}
int main() {
  scanf("%d", &n);
  for (Cn3 = 1.0 * n * (n - 1) * (n - 2) / 6, ans = 0, i = 1; i < n; ++i) {
    scanf("%d%d%lf", &u, &v, &w[i]);
    t.to = v, t.no = i;
    g[u].push_back(t);
    t.to = u, t.no = i;
    g[v].push_back(t);
  }
  dfs(1, 0);
  for (i = 1; i < n; ++i) ans += count(i);
  scanf("%d", &q);
  while (q--) {
    scanf("%d%lf", &x, &y);
    ans -= count(x);
    w[x] = y;
    ans += count(x);
    printf("%.9lf\n", ans);
  }
}
