#include <bits/stdc++.h>
using namespace std;
int weight[(100000 + 50)];
long long int cuts[(100000 + 50)];
long long int counter[(100000 + 50)];
vector<pair<int, int> > tree[(100000 + 50)];
double e;
double m;
int n, q;
void dfs(int prev, int curr) {
  counter[curr] = 1;
  for (int i = 0; i < tree[curr].size(); i++) {
    int next = tree[curr][i].first;
    int edge = tree[curr][i].second;
    if (prev == next) continue;
    dfs(curr, next);
    counter[curr] += counter[next];
    long long int lft = counter[next];
    long long int rht = n - lft;
    long long int tot = 0;
    if (1 != rht) tot += lft * ((rht * (rht - 1)) / 2);
    if (1 != lft) tot += rht * ((lft * (lft - 1)) / 2);
    cuts[edge] = tot;
  }
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin >> n;
  int a, b;
  m = 1.0 * n * (n - 1) * (n - 2) / 6.0;
  for (int i = 1; i <= n - 1; i++) {
    cin >> a >> b >> weight[i];
    tree[a].push_back(make_pair(b, i));
    tree[b].push_back(make_pair(a, i));
  }
  dfs(0, a);
  e = 0.0;
  for (int i = 1; i <= n - 1; i++) e += cuts[i] * 2.0 * weight[i];
  cin >> q;
  cout << fixed << setprecision(10);
  int r, w;
  for (int i = 1; i <= q; i++) {
    cin >> r >> w;
    e -= cuts[r] * 2.0 * (weight[r] - w);
    weight[r] = w;
    cout << e / m << "\n";
  }
  return 0;
}
