#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[100009];
int n, a[100009], b[100009], q;
long long c[100009], cnt[100009];
long double re;
bool visit[100009];
void input() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d %d %I64d", &a[i], &b[i], &c[i]);
    v[a[i]].push_back(pair<int, int>(b[i], i));
    v[b[i]].push_back(pair<int, int>(a[i], i));
  }
}
long long dfs(int cur, int p, int dNum) {
  visit[cur] = 1;
  long long un = 0;
  for (int i = 0; i < v[cur].size(); i++) {
    if (!visit[v[cur][i].first])
      un += dfs(v[cur][i].first, cur, v[cur][i].second);
  }
  if (cur != 1 || p != 1) cnt[dNum] = (un + 1) * (n - un - 1);
  return un + 1;
}
void solve() {
  input();
  dfs(1, 1, 1);
  for (int i = 1; i < n; i++) {
    re += (long double)c[i] * (long double)cnt[i] / (long double)n * 2 /
          (long double)(n - 1) * 3;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    long long x, y;
    scanf("%I64d %I64d", &x, &y);
    re -= (long double)c[x] * (long double)cnt[x] / (long double)n * 2 /
          (long double)(n - 1) * 3;
    c[x] = y;
    re += (long double)c[x] * (long double)cnt[x] / (long double)n * 2 /
          (long double)(n - 1) * 3;
    printf("%.10Lf\n", re);
  }
}
int main(void) {
  solve();
  return 0;
}
