#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
vector<pair<int, int> > edge[N];
int size[N], len[N];
long long cnt[N];
long long C(long long n, long long k) { return (n * (n - 1)) / (1 * 2); }
long long compute(int t) {
  long long x = t, y = n - t, sum = 0;
  sum = C(x, 2) * y + C(y, 2) * x;
  return sum;
}
void DFS(int u, int p) {
  size[u] = 1;
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i].first;
    int id = edge[u][i].second;
    if (v == p) continue;
    DFS(v, u);
    size[u] += size[v];
    cnt[id] = compute(size[v]);
  }
}
int main() {
  int i, j;
  cin >> n;
  for (i = 1; i <= n - 1; i++) {
    int u, v, l;
    cin >> u >> v >> l;
    edge[u].push_back(pair<int, int>(v, i));
    edge[v].push_back(pair<int, int>(u, i));
    len[i] = l;
  }
  DFS(1, 0);
  long long total = ((long long)n * (n - 1) * (n - 2)) / (1 * 2 * 3);
  double sum = 0, ans;
  for (i = 1; i <= n - 1; i++) sum += (double)cnt[i] * len[i] * 2;
  ans = sum / total;
  int q;
  cin >> q;
  while (q--) {
    int id, w;
    cin >> id >> w;
    ans -= (double)cnt[id] * (len[id] - w) * 2 / total;
    len[id] = w;
    cout << fixed << setprecision(10) << ans << endl;
  }
  return 0;
}
