#include <bits/stdc++.h>
using namespace std;
vector<long long> g[100000 + 10];
map<pair<long long, long long>, long long> mp;
map<long long, pair<long long, long long> > road;
long long cnt[100000 + 10];
long long ans = 0;
int visited[100000 + 10];
int L[100000 + 100];
long long n;
void dfs(long long u) {
  visited[u] = 1;
  long long l = g[u].size();
  cnt[u] = 1;
  for (int i = 0; i < l; i++) {
    long long v = g[u][i];
    if (visited[v] == 0) {
      L[v] = L[u] + 1;
      visited[v] = 1;
      dfs(v);
      cnt[u] += cnt[v];
      ans += mp[make_pair(u, v)] * cnt[v] * (n - cnt[v]);
    }
  }
}
int main() {
  scanf("%lld", &(n));
  for (int i = 1; i < n; i++) {
    long long u, v, w;
    scanf("%lld", &(u));
    scanf("%lld", &(v));
    scanf("%lld", &(w));
    g[u].push_back(v);
    g[v].push_back(u);
    mp[make_pair(u, v)] = w;
    mp[make_pair(v, u)] = w;
    road[i] = make_pair(u, v);
  }
  L[1] = 1;
  dfs(1);
  int q;
  scanf("%d", &(q));
  while (q--) {
    long long r;
    long long w;
    scanf("%lld", &(r));
    scanf("%lld", &(w));
    pair<long long, long long> x;
    x = road[r];
    if (L[x.first] > L[x.second]) {
      long long tmp = x.first;
      x.first = x.second;
      x.second = tmp;
    }
    ans += (cnt[x.second]) * (n - cnt[x.second]) * (w - mp[x]);
    mp[x] = w;
    mp[make_pair(x.second, x.first)] = w;
    double num = ans * 6.0 / (n * (n - 1));
    printf("%.10f\n", num);
  }
  return 0;
}
