#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > pq;
int n;
int a[1000006], b[1000006], l[1000006], deep[1000006], cnt[1000006];
vector<int> edge[1000006];
void dfs(int ch, int fa) {
  cnt[ch] = 1;
  deep[ch] = deep[fa] + 1;
  int u;
  for (int i = 0; i < edge[ch].size(); i++) {
    u = edge[ch][i];
    if (u == fa) continue;
    dfs(u, ch);
    cnt[ch] += cnt[u];
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a[i] >> b[i] >> l[i];
    edge[a[i]].push_back(b[i]);
    edge[b[i]].push_back(a[i]);
  }
  dfs(1, 0);
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    if (deep[a[i]] < deep[b[i]]) swap(a[i], b[i]);
    ans += 6.0 * l[i] * cnt[a[i]] / (n - 1) * (n - cnt[a[i]]) / n;
  }
  int q;
  cin >> q;
  int r, w;
  for (int i = 0; i < q; i++) {
    int r, w;
    scanf("%d%d", &r, &w);
    ans -= 6.0 * l[r] * cnt[a[r]] / (n - 1) * (n - cnt[a[r]]) / n;
    l[r] = w;
    ans += 6.0 * l[r] * cnt[a[r]] / (n - 1) * (n - cnt[a[r]]) / n;
    printf("%.10f\n", ans);
  }
  return 0;
}
