#include <bits/stdc++.h>
using namespace std;
long long n, a[100005], b[100005], l[100005], q, r, w, cur, deg[100005],
    below[100005], dp[100005], u, v;
vector<int> adj[100005];
queue<int> Q;
map<pair<int, int>, long long> edge;
long long bel(int x) {
  if (~below[x]) return below[x];
  below[x] = 0;
  for (int i : adj[x])
    if (deg[i] > deg[x]) below[x] += 1 + bel(i);
  return below[x];
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i] >> l[i];
    adj[a[i]].push_back(b[i]);
    adj[b[i]].push_back(a[i]);
    edge[{a[i], b[i]}] = edge[{b[i], a[i]}] = l[i];
  }
  cin >> q;
  deg[1] = 1;
  Q.push(1);
  while (!Q.empty()) {
    cur = Q.front();
    Q.pop();
    for (int i : adj[cur])
      if (!deg[i]) {
        deg[i] = deg[cur] + 1;
        Q.push(i);
      }
  }
  memset(below, -1, sizeof(below));
  for (int i = n; i; i--) bel(i);
  cur = 0;
  for (int i = 0; i < n - 1; i++) {
    u = a[i];
    v = b[i];
    if (deg[v] > deg[u]) swap(u, v);
    cur += l[i] * (below[u] + 1) * (n - 1 - below[u]);
  }
  while (q--) {
    cin >> r >> w;
    r--;
    u = a[r];
    v = b[r];
    if (deg[v] > deg[u]) swap(u, v);
    cur -= (l[r] - w) * (1 + below[u]) * (n - 1 - below[u]);
    printf("%.10f\n", cur * 6.0 / (n * (n - 1)));
    l[r] = w;
  }
}
