#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, m, q;
struct edge {
  long long u, v, w;
};
long long calc(long long a) {
  long long ans = 1;
  ans = ans * a * (a - 1) * (a - 2);
  ans = ans / 6;
  return ans;
}
long long dp[N];
bool mark[N];
vector<long long> graph[N];
vector<edge> vec;
void dfs(long long v) {
  mark[v] = true;
  for (auto u : graph[v]) {
    if (!mark[u]) {
      dfs(u);
      dp[v] += dp[u];
    }
  }
  dp[v]++;
}
int main() {
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    edge tmp;
    tmp.u = u - 1;
    tmp.v = v - 1;
    tmp.w = w;
    vec.push_back(tmp);
    graph[u - 1].push_back(v - 1);
    graph[v - 1].push_back(u - 1);
  }
  dfs(0);
  long double ans = 0;
  for (auto e : vec) {
    long long u, v, w;
    u = e.u;
    v = e.v;
    w = e.w;
    long long alpha = min(dp[u], dp[v]);
    long long cnt = calc(n) - calc(alpha) - calc(n - alpha);
    cnt = cnt * 2 * w;
    ans += cnt;
  }
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long tmp, w, u, v;
    cin >> tmp >> w;
    tmp--;
    u = vec[tmp].u;
    v = vec[tmp].v;
    long long alpha = min(dp[u], dp[v]);
    long long cnt = calc(n) - calc(alpha) - calc(n - alpha);
    cnt = cnt * 2 * (vec[tmp].w - w);
    vec[tmp].w = w;
    ans -= cnt;
    double t = ans;
    t = t / calc(n);
    cout << setprecision(9) << t << endl;
  }
}
