#include <bits/stdc++.h>
using namespace std;
inline long long ceil(long long a, long long b) { return (a + b - 1) / b; }
const long long N = 1e5 + 5;
list<pair<long long, long long> > adj[N];
long long n, par[N], parWt[N], sz[N], cost = 0;
void dfs(long long v = 1, long long pv = 0) {
  sz[v]++;
  for (auto i : adj[v]) {
    if (i.first == pv) continue;
    par[i.first] = v;
    parWt[i.first] = i.second;
    dfs(i.first, v);
    sz[v] += sz[i.first];
  }
  cost += (sz[v] * (n - sz[v]) * parWt[v]);
}
void func() {
  cin >> n;
  pair<long long, long long> edge[n];
  for (long long i = 1; i < n; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
    edge[i] = {u, v};
  }
  dfs();
  long long q;
  cin >> q;
  while (q--) {
    long long r, w;
    cin >> r >> w;
    long long u = edge[r].first, v = edge[r].second;
    long long x;
    if (u == par[v])
      x = v;
    else
      x = u;
    cost -= (sz[x] * (n - sz[x]) * (parWt[x] - w));
    parWt[x] = w;
    double ans = ((double)cost * 6) / ((double)n * (n - 1));
    printf("%.8f\n", ans);
  }
}
int main() {
  long long ntc = 1;
  for (long long i = 1; i < ntc + 1; i++) {
    func();
  }
  return 0;
}
