#include <bits/stdc++.h>
using namespace std;
long long n, a[100005], b[100005], q;
long double ans, totalsum = 0, sum = 0, w[100005], f[100005];
vector<pair<long long, long long> > graph[100005];
bool vis[100005];
void dfs(long long u) {
  vis[u] = 1;
  f[u] = 1;
  for (int i = 0; i < graph[u].size(); i++) {
    long long v = graph[u][i].first;
    if (vis[v] == 0) {
      dfs(v);
      f[u] += f[v];
    }
  }
}
int main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    cin >> a[i] >> b[i] >> w[i];
    graph[a[i]].push_back(make_pair(b[i], w[i]));
    graph[b[i]].push_back(make_pair(a[i], w[i]));
  }
  dfs(1);
  for (int i = 1; i <= n - 1; i++) {
    int u = a[i], v = b[i];
    if (f[v] > f[u]) swap(v, u);
    sum += 2 * w[i] * (f[v]) * (f[1] - f[v]);
  }
  totalsum = 3 * sum;
  cin >> q;
  long long cost, k;
  while (q--) {
    cin >> k >> cost;
    int u = a[k], v = b[k];
    if (f[v] > f[u]) swap(v, u);
    totalsum -= 6 * (w[k] - cost) * f[v] * (f[1] - f[v]);
    w[k] = cost;
    ans = (long double)(totalsum) / (long double)(n * (n - 1));
    cout << setprecision(12) << fixed << ans << "\n";
  }
}
