#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > G;
map<pair<int, int>, int> ind;
vector<int> l, c;
int dfs(int pr, int u) {
  int res = 0;
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (v != pr) {
      pair<int, int> cur(u, v);
      if (ind.count(cur) == 0) swap(cur.first, cur.second);
      int j = ind[cur];
      c[j] = dfs(u, v);
      res += c[j];
    }
  }
  return res + 1;
}
int main() {
  cin >> n;
  G.assign(n, vector<int>());
  c.assign(n - 1, -1);
  l.assign(n - 1, 0);
  int a, b;
  for (int(i) = (0); (i) < (n - 1); ++(i)) {
    cin >> a >> b >> l[i];
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
    ind[make_pair(a, b)] = i;
  }
  dfs(-1, 0);
  long double res = 0;
  for (int(i) = (0); (i) < (n - 1); ++(i)) {
    int c1 = c[i];
    int c2 = n - c1;
    res += l[i] * 1LL *
           (c1 * 1LL * (c1 - 1) * 1LL * c2 + c1 * 1LL * c2 * 1LL * (c2 - 1));
  }
  long long div = n * 1LL * (n - 1) * 1LL * (n - 2) / 6;
  int q;
  cin >> q;
  cout << fixed;
  cout.precision(12);
  while (q--) {
    int r, w;
    cin >> r >> w;
    r--;
    int c1 = c[r];
    int c2 = n - c1;
    int d = l[r] - w;
    l[r] = w;
    res -= d * 1LL *
           (c1 * 1LL * (c1 - 1) * 1LL * c2 + c1 * 1LL * c2 * 1LL * (c2 - 1));
    cout << res / div << endl;
  }
  return 0;
}
