#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj;
vector<bool> vis;
vector<long long int> len, cnt;
map<pair<int, int>, int> hsh;
int dfs(int v) {
  vis[v] = 1;
  int val = 1;
  for (int u : adj[v]) {
    if (!vis[u]) {
      cnt[hsh[{u, v}]] = dfs(u);
      val += cnt[hsh[{u, v}]];
    }
  }
  return val;
}
int main() {
  cout << fixed << setprecision(7);
  long long int n;
  int u, v, i, q;
  cin >> n;
  adj.assign(n + 1, {});
  vis.assign(n + 1, 0);
  len.assign(n, 0);
  cnt = len;
  for (i = 1; i < n; i++) {
    cin >> u >> v >> len[i];
    adj[u].push_back(v);
    adj[v].push_back(u);
    hsh[{u, v}] = i;
    hsh[{v, u}] = i;
  }
  dfs(1);
  double ans = 0, tot = (double)(n * (n - 1) * (n - 2)) / 6;
  for (i = 1; i < n; i++)
    ans += (double)len[i] *
           ((cnt[i] * (cnt[i] - 1) * (n - cnt[i]) +
             (cnt[i] * (n - cnt[i]) * (n - cnt[i] - 1)))) /
           2;
  cin >> q;
  while (q--) {
    cin >> i >> v;
    ans -= (double)(len[i] - v) *
           ((cnt[i] * (cnt[i] - 1) * (n - cnt[i]) +
             (cnt[i] * (n - cnt[i]) * (n - cnt[i] - 1)))) /
           2;
    len[i] = v;
    cout << 2 * ans / tot << endl;
  }
}
