#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 10;
int n, q, U[N], V[N], W[N], sz[N], h[N];
vector<int> adj[N];
double ans, prop;
void dfs(int v = 0, int par = -1) {
  sz[v] = 1;
  for (int u : adj[v])
    if (u ^ par) h[u] = h[v] + 1, dfs(u, v), sz[v] += sz[u];
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cout << setprecision(8) << fixed;
  cin >> n;
  prop = 1ll * n * (n - 1) * (n - 2) / 6;
  for (int i = 0; i < n - 1; i++)
    cin >> U[i] >> V[i] >> W[i], adj[--U[i]].push_back(--V[i]),
        adj[V[i]].push_back(U[i]);
  dfs();
  for (int i = 0; i < n - 1; i++) {
    if (h[U[i]] > h[V[i]]) swap(U[i], V[i]);
    long long x = n - sz[V[i]];
    double sv = sz[V[i]] * x * (x - 1) + x * sz[V[i]] * (sz[V[i]] - 1);
    ans += W[i] * sv / prop;
  }
  int r, w;
  cin >> q;
  while (q--) {
    cin >> r >> w, --r;
    long long x = n - sz[V[r]];
    double sv = sz[V[r]] * x * (x - 1) + x * sz[V[r]] * (sz[V[r]] - 1);
    ans -= W[r] * sv / prop;
    ans += w * sv / prop;
    ;
    W[r] = w;
    cout << ans << '\n';
  }
}
