#include <bits/stdc++.h>
using namespace std;
vector<long long int> g[100005];
vector<pair<long long int, long long int> > ed;
vector<long long int> w;
vector<long long int> eff;
long long int vis[100005];
long long int val[100005];
long long int rec(long long int i) {
  if (vis[i] != 1) {
    vis[i] = 1;
    long long int cur = 1, j;
    for (j = 0; j < g[i].size(); ++j) {
      cur += rec(g[i][j]);
    }
    val[i] = cur;
    return cur;
  } else
    return 0;
}
int main() {
  long long int n, i, y, r, c;
  cin >> n;
  for (i = 0; i < n - 1; ++i) {
    long long int t1, t2, t3;
    cin >> t1 >> t2 >> t3;
    g[t1].push_back(t2);
    g[t2].push_back(t1);
    ed.push_back(make_pair(t1, t2));
    w.push_back(t3);
  }
  rec(1);
  for (i = 0; i < n - 1; ++i) {
    long long int ef = 0;
    if (val[ed[i].first] > val[ed[i].second]) {
      ef = val[ed[i].second] * (n - val[ed[i].second]);
    } else {
      ef = val[ed[i].first] * (n - val[ed[i].first]);
    }
    eff.push_back(ef);
  }
  double ans = 0;
  for (i = 0; i < eff.size(); ++i) {
    ans = ans + (eff[i] * (double)w[i]);
  }
  cin >> y;
  for (i = 0; i < y; ++i) {
    cin >> r >> c;
    ans = ans - (eff[r - 1] * (double)(w[r - 1] - (double)c));
    w[r - 1] = c;
    printf("%0.8lf\n", ans * ((n - 2) * 6) / (n * (n - 1) * (n - 2)));
  }
  return 0;
}
