#include <bits/stdc++.h>
using namespace std;
int n, a, b, l, q, r, w;
vector<pair<int, int> > adj[600005];
double roads[600005], roadsj[600005];
double subnodes[600005];
double prob[600005];
bool vis[600005];
void dfs(int no) {
  vis[no] = true;
  subnodes[no] = 1;
  for (auto j : adj[no]) {
    if (!vis[j.first]) {
      dfs(j.first);
      subnodes[no] += subnodes[j.first];
      prob[j.second] =
          subnodes[j.first] * ((double)n - subnodes[j.first]) * roads[j.second];
      roadsj[j.second] = subnodes[j.first];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a >> b >> l;
    roads[i] = l;
    adj[a].push_back({b, i});
    adj[b].push_back({a, i});
  }
  dfs(1);
  cin >> q;
  double specialnn = n;
  specialnn *= (double)(n - 1);
  double totalprob = 0;
  for (int i = 1; i < n; i++) {
    totalprob += (prob[i] /= specialnn);
  }
  for (int i = 0; i < q; i++) {
    cin >> r >> w;
    totalprob -= prob[r];
    prob[r] = roadsj[r] * ((double)n - roadsj[r]) * (roads[r] = w) / specialnn;
    totalprob += prob[r];
    cout << setprecision(10) << fixed << totalprob * 6 << endl;
  }
}
