#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100010], b[100010], len[100010], cnt[100010];
vector<int> g[100010];
int dfs(int u, int fa) {
  cnt[u] = 1;
  for (int i = 0; i < (int)g[u].size(); ++i) {
    if (g[u][i] == fa) continue;
    dfs(g[u][i], u);
    cnt[u] += cnt[g[u][i]];
  }
  return cnt[u];
}
int main() {
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; ++i) g[i].clear();
    for (int i = 0; i < n - 1; ++i) {
      scanf("%d%d%d", &a[i], &b[i], &len[i]);
      a[i]--;
      b[i]--;
      g[a[i]].push_back(b[i]);
      g[b[i]].push_back(a[i]);
    }
    dfs(0, -1);
    double C[100010];
    for (int i = 0; i < n - 1; ++i) {
      long long v = min(cnt[a[i]], cnt[b[i]]);
      C[i] = (double)v * (n - v) * (n - 2);
    }
    double res = 0;
    for (int i = 0; i < n - 1; ++i) {
      res += C[i] * len[i];
    }
    double x = (double)n * (n - 1) * (n - 2) / 6;
    scanf("%d", &m);
    for (int i = 0; i < m; ++i) {
      int r, w;
      scanf("%d%d", &r, &w);
      r--;
      res -= C[r] * (len[r] - w);
      len[r] = w;
      printf("%.10lf\n", res / x);
    }
  }
  return 0;
}
