#include <bits/stdc++.h>
using namespace std;
long long n, q;
struct EDGE {
  int v, inx;
  long long w;
};
vector<EDGE> edges[100010];
long long son[100010];
double tot;
long long cnt[100010], wet[100010];
void dfs(int u, int par) {
  son[u] = 1;
  for (int i = 0; i < edges[u].size(); ++i) {
    EDGE edge = edges[u][i];
    if (edge.v == par) {
      continue;
    }
    dfs(edge.v, u);
    long long num = 0LL;
    if (n - son[edge.v] >= 2) {
      num += son[edge.v] * (n - son[edge.v]) * (n - son[edge.v] - 1LL);
    }
    if (son[edge.v] >= 2) {
      num += (n - son[edge.v]) * son[edge.v] * (son[edge.v] - 1LL);
    }
    cnt[edge.inx] = num;
    tot += cnt[edge.inx] * wet[edge.inx];
    son[u] += son[edge.v];
  }
}
int main() {
  int u, v;
  long long w;
  int num;
  long long cur;
  while (cin >> n) {
    for (int i = 1; i <= n; ++i) {
      edges[i].clear();
    }
    for (int i = 1; i < n; ++i) {
      cin >> u >> v >> w;
      EDGE edge;
      edge.v = v;
      edge.w = w;
      edge.inx = i;
      edges[u].push_back(edge);
      edge.v = u;
      edges[v].push_back(edge);
      wet[i] = w;
    }
    tot = 0;
    memset(son, 0, sizeof(son));
    dfs(1, 0);
    cin >> q;
    while (q-- > 0) {
      cin >> num >> cur;
      tot -= (wet[num] - cur) * cnt[num];
      wet[num] = cur;
      double down = (double)(n * (n - 1) * (n - 2)) / 6.0;
      double ans = tot / down;
      printf("%.10lf\n", ans);
    }
  }
  return 0;
}
