#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > g;
vector<pair<int, int> > gg;
vector<vector<int> > vals;
vector<int> psi, vs;
int N;
int dfs1(int n, int parent = -1) {
  int ret = 1;
  vals[n].resize(g[n].size());
  for (int i = 0; i < g[n].size(); i++) {
    if (g[n][i].first != parent) {
      ret += (vals[n][i] = dfs1(g[n][i].first, n));
    } else {
      psi[n] = i;
    }
  }
  return vs[n] = ret;
}
void dfs2(int n, int parent = -1) {
  if (parent != -1) {
    vals[n][psi[n]] = N - vs[n];
  }
  for (int i = 0; i < g[n].size(); i++) {
    if (g[n][i].first != parent) {
      dfs2(g[n][i].first, n);
    }
  }
}
int main() {
  int n;
  cin >> n;
  g.resize(n);
  N = n;
  gg.resize(n - 1);
  vector<pair<int, int> > es;
  vector<int> ws(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b, l;
    cin >> a >> b >> l;
    a--, b--;
    gg[i].first = g[a].size();
    gg[i].second = g[b].size();
    g[a].push_back(make_pair(b, l));
    g[b].push_back(make_pair(a, l));
    es.push_back(make_pair(a, b));
    ws[i] = l;
  }
  psi.resize(n);
  vs.resize(n);
  vals.resize(n);
  dfs1(0);
  dfs2(0);
  vector<long double> tp(n - 1);
  long double bigtotal = 0;
  long double nn = n;
  for (int i = 0; i < n - 1; i++) {
    long double s1 = n - vals[es[i].first][gg[i].first];
    long double s2 = n - vals[es[i].second][gg[i].second];
    long double total = (s1 / nn * s2 / (nn - 1) * (s2 - 1) / (nn - 2) +
                         s1 / nn * s2 / (nn - 1) * (s1 - 1) / (nn - 2)) *
                        6.0;
    bigtotal += total * ws[i];
    tp[i] = total;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int r;
    long double w;
    cin >> r >> w;
    r--;
    bigtotal -= tp[r] * (ws[r] - w);
    ws[r] = w;
    cout << setprecision(7) << fixed << bigtotal << endl;
  }
  return 0;
}
