#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[200000 + 10];
map<pair<int, int>, int> mp;
int W[200000 + 10], lef[200000 + 10], ri[200000 + 10];
bool vis[200000 + 10];
int DFS(int s) {
  vis[s] = 1;
  int ch = 1, tmp = 0;
  for (int i = 0; i < (int)adj[s].size(); i++) {
    int v = adj[s][i];
    if (vis[v]) continue;
    tmp = DFS(v);
    int edgenum = mp[make_pair(max(s, v), min(s, v))];
    lef[edgenum] = tmp;
    ri[edgenum] = n - tmp;
    ch += tmp;
  }
  return ch;
}
double ans;
void CALC() {
  for (int i = 1; i < n; i++) {
    ans += (3. * (double)lef[i] * (double)ri[i] * (double)W[i]) /
           ((double)(n - 1) * (double)n);
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  int u, v, w, q;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v >> w;
    mp[make_pair(max(u, v), min(u, v))] = i + 1;
    W[i + 1] = w;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  DFS(1);
  ans = 0.;
  CALC();
  cin >> q;
  while (q--) {
    cin >> v >> w;
    ans -= (3. * (double)lef[v] * (double)ri[v] * (double)W[v]) /
           ((double)(n - 1) * (double)n);
    W[v] = w;
    ans += (3. * (double)lef[v] * (double)ri[v] * (double)W[v]) /
           ((double)(n - 1) * (double)n);
    printf("%.12lf\n", ans * 2.);
  }
  return 0;
}
