#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 16) + 5;
const int MAXN = 1e5 + 5;
struct E {
  int to, sn;
};
vector<E> edge[MAXN];
int n, q;
double qw[MAXN];
int num[MAXN];
bool vis[MAXN];
int cost[MAXN];
void pre(int u) {
  vis[u] = 1;
  num[u] = 1;
  for (int i = 0; i < edge[u].size(); i++) {
    int nx = edge[u][i].to;
    if (vis[nx]) continue;
    pre(nx);
    num[u] += num[nx];
  }
}
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < edge[u].size(); i++) {
    int nx = edge[u][i].to;
    if (vis[nx]) continue;
    int es = edge[u][i].sn;
    if (qw[es]) continue;
    qw[es] =
        3.0 * ((double)num[nx] / n) * 2 * ((double)(n - num[nx]) / (n - 1.0));
    dfs(nx);
  }
}
int main(int argc, char* argv[]) {
  cin >> n;
  int u, v, c;
  for (int i = 1; i < n; i++) {
    cin >> u >> v >> c;
    edge[u].push_back({v, i});
    edge[v].push_back({u, i});
    cost[i] = c;
  }
  memset(vis, 0, sizeof(vis));
  pre(1);
  memset(vis, 0, sizeof(vis));
  dfs(1);
  double ans = 0;
  for (int i = 1; i < n; i++) ans += (qw[i] * cost[i]);
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int dif = cost[a] - b;
    cost[a] = b;
    ans -= (qw[a] * dif);
    printf("%.10lf\n", ans);
  }
  return 0;
}
