#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > ad;
map<int, pair<long long, long long> > turno;
map<pair<long long, long long>, long long> edges;
long long hijos[100010];
int visit[100010];
map<pair<long long, long long>, long long> prod;
void dfs(int u) {
  visit[u] = 1;
  for (int i = 0; i < ad[u].size(); i++) {
    int v = ad[u][i];
    if (!visit[v]) {
      dfs(v);
      hijos[u] += hijos[v];
    }
  }
  hijos[u]++;
}
int main() {
  long long n, m;
  cin >> n;
  ad.assign(n, vector<long long>(0));
  for (long long i = 0; i < n - 1; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    ad[a].push_back(b);
    ad[b].push_back(a);
    long long may = max(a, b);
    long long men = min(a, b);
    turno[i + 1] = make_pair(may, men);
    edges[make_pair(may, men)] = c;
  }
  dfs(0);
  vector<pair<pair<int, int>, long long> > w(edges.begin(), edges.end());
  int len = w.size();
  for (int i = 0; i < len; i++) {
    long long u = w[i].first.first, v = w[i].first.second;
    long long r = min(hijos[u], hijos[v]);
    prod[make_pair(u, v)] = r * (n - r);
  }
  long long inicio = 0;
  for (int i = 0; i < len; i++) {
    long long sum;
    long long u = w[i].first.first, v = w[i].first.second;
    long long cos = w[i].second;
    sum = prod[make_pair(u, v)] * cos;
    inicio += sum;
  }
  cin >> m;
  long long div = n * (n - 1);
  for (int i = 0; i < m; i++) {
    int r;
    cin >> r;
    long long costant = edges[turno[r]];
    long long newcost;
    cin >> newcost;
    inicio = inicio - prod[turno[r]] * (costant - newcost);
    edges[turno[r]] = newcost;
    double ans = 0.0;
    ans = (6.0 * inicio) / (1.0 * div);
    printf("%.8lf\n", ans);
  }
  return 0;
}
