#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
using namespace std;
const int N = 100005, INF = 0x3f3f3f3f;
int x, m, u[N], v[N];
long long n, size[N];
double ans, y, add[N], conbine, c[N];
struct edge {
  int v, id;
  double c;
};
vector<edge> G[N];
void Add(int x, int y, double z, int id) {
  G[x].push_back(edge{y, id, z});
  G[y].push_back(edge{x, id, z});
}
void DFS(int u, int f) {
  size[u] = 1;
  for (register int i = 0; i < (int)G[u].size(); i++) {
    if (G[u][i].v == f) continue;
    int v = G[u][i].v;
    DFS(v, u);
    add[G[u][i].id] =
        6.0 * (double)(max(0LL, size[v] * (n - size[v]) * (n - size[v] - 1)) +
                       max(0LL, size[v] * (size[v] - 1) * (n - size[v])));
    ans += add[G[u][i].id] * G[u][i].c;
    size[u] += size[v];
  }
}
signed main() {
  scanf("%lld", &n);
  conbine = 1.0 * n * (n - 1) * (n - 2);
  for (register int i = 1; i < n; i++) {
    scanf("%d%d%lf", u + i, v + i, c + i);
    Add(u[i], v[i], c[i], i);
  }
  DFS(1, 0);
  scanf("%d", &m);
  for (register int i = 1; i <= m; i++) {
    scanf("%d%lf", &x, &y);
    ans -= (c[x] - y) * add[x];
    c[x] = y;
    printf("%.10lf\n", ans / conbine);
  }
  return 0;
}
