#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100009;
vector<int> G[MAXN];
struct edge {
  int u, v, w;
};
edge E[MAXN];
long long sz[MAXN], contr[MAXN];
void dfs(int node, int par) {
  sz[node] = (long long)1;
  for (int i = 0; i < G[node].size(); i++) {
    int v = G[node][i];
    if (v == par) continue;
    dfs(v, node);
    sz[node] += sz[v];
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    E[i].u = u;
    E[i].v = v;
    E[i].w = w;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, -1);
  double s = 0;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    u = E[i].u;
    v = E[i].v;
    long long a = min(sz[u], sz[v]), b;
    b = n - a;
    contr[i] = 2 * a * b;
    s += (double)contr[i] * E[i].w;
  }
  double d = n;
  d *= (double)(n - 1);
  int q;
  cin >> q;
  while (q--) {
    int p, w;
    cin >> p >> w;
    s += (double)contr[p] * (w - E[p].w);
    double ans = s * 3.0;
    ans /= d;
    E[p].w = w;
    printf("%.12lf\n", ans);
  }
  return 0;
}
