#include <bits/stdc++.h>
using namespace std;
struct edge {
  int a, b, l;
};
int n, q;
edge e[100010];
vector<int> v[100010];
int sz[100010];
long long sum;
int dfs(int u, int p) {
  sz[u] = 1;
  for (int i = 0; i < v[u].size(); i++) {
    int x = v[u][i];
    if (x == p) continue;
    if (e[x].a == u) swap(e[x].a, e[x].b);
    sz[u] += dfs(e[x].a, x);
  }
  sum += (long long)sz[u] * (n - sz[u]) * e[p].l;
  return sz[u];
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> e[i].a >> e[i].b >> e[i].l;
    v[e[i].a].push_back(i);
    v[e[i].b].push_back(i);
  }
  dfs(1, 0);
  double k = 6.0 / n / (n - 1);
  cin >> q;
  while (q--) {
    int r, w;
    cin >> r >> w;
    int u = e[r].a;
    sum -= (long long)sz[u] * (n - sz[u]) * e[r].l;
    e[r].l = w;
    sum += (long long)sz[u] * (n - sz[u]) * e[r].l;
    cout << fixed << setprecision(15) << k * sum << '\n';
  }
}
