#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, q, u[N], v[N], x;
long long size[N], d[N];
double w[N], tot, ans, y;
long long cnt, head[N];
struct edge {
  long long next, to;
  double w;
} e[N << 1];
inline void add(long long u, long long v, double w) {
  cnt++;
  e[cnt].next = head[u];
  e[cnt].to = v;
  e[cnt].w = w;
  head[u] = cnt;
}
void dfs(long long u, long long fa) {
  size[u] = 1;
  for (register long long i = head[u]; i; i = e[i].next)
    if (e[i].to != fa) {
      d[e[i].to] = d[u] + 1;
      dfs(e[i].to, u);
      size[u] += size[e[i].to];
    }
}
signed main() {
  scanf("%lld", &n);
  tot = n * (n - 1) * (n - 2) / 6;
  for (register long long i = 1; i < n; ++i) {
    scanf("%lld%lld%lf", &u[i], &v[i], &w[i]);
    add(u[i], v[i], w[i]);
    add(v[i], u[i], w[i]);
  }
  d[1] = 1;
  dfs(1, 0);
  for (register long long i = 1; i < n; ++i) {
    if (d[v[i]] < d[u[i]]) swap(v[i], u[i]);
    ans += size[v[i]] * (n - size[v[i]]) * (n - 2) * w[i];
  }
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld%lf", &x, &y);
    double del = w[x] - y;
    w[x] = y;
    ans -= size[v[x]] * (n - size[v[x]]) * (n - 2) * del;
    printf("%.10f\n", ans / tot);
  }
  return 0;
}
