#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
int n, q;
int len[N];
vector<pair<int, int>> g[N];
double prob[N];
double sum;
int dfs(int v, int p) {
  int size = 1;
  for (auto e : g[v]) {
    int to = e.first;
    int ind = e.second;
    int w = len[ind];
    if (to == p) continue;
    int A = dfs(to, v);
    size += A;
    int B = n - A;
    double prob_nom = (long long)A * B * (B - 1) / 2;
    prob_nom += (long long)B * A * (A - 1) / 2;
    double prob_denom = (long long)n * (n - 1) * (n - 2) / 6;
    prob[ind] = prob_nom / prob_denom;
    sum += w * prob[ind];
  }
  return size;
}
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    len[i] = w;
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  dfs(0, -1);
  0;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int r, w;
    scanf("%d%d", &r, &w);
    r--;
    double delta = w - len[r];
    sum += delta * prob[r];
    len[r] = w;
    printf("%.10lf\n", 2 * sum);
  }
}
int main() {
  solve();
  0;
  return 0;
}
