#include <bits/stdc++.h>
using namespace std;
struct edge {
  int next, to;
} e[100005 << 1];
long long total = 0, edges = 0;
long long cnt[100005];
int n, s[100005], f[100005], head[100005];
void finds(int x, int fa) {
  f[x] = fa;
  s[x] = 1;
  for (int now = head[x], v; now; now = e[now].next) {
    v = e[now].to;
    if (v != fa) {
      finds(v, x);
      s[x] += s[v];
    }
  }
}
int u[100005], v[100005], w[100005];
int main() {
  scanf("%d", &n);
  edges = ((long long)n * (n - 1)) >> 1;
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", u + i, v + i, w + i);
    e[i << 1].to = v[i], e[i << 1].next = head[u[i]], head[u[i]] = i << 1;
    e[(i << 1) | 1].to = u[i], e[(i << 1) | 1].next = head[v[i]],
                 head[v[i]] = (i << 1) | 1;
  }
  finds(1, 0);
  for (int i = 1; i < n; i++) {
    if (f[u[i]] == v[i]) {
      cnt[i] = (long long)s[u[i]] * (n - s[u[i]]);
    } else {
      cnt[i] = (long long)s[v[i]] * (n - s[v[i]]);
    }
    total += cnt[i] * w[i];
  }
  int q;
  scanf("%d", &q);
  for (int i = 1, x, d; i <= q; i++) {
    scanf("%d%d", &x, &d);
    total -= cnt[x] * (w[x] - d);
    w[x] = d;
    printf("%.10lf\n", total * 3.0 / edges);
  }
  return 0;
}
