#include <bits/stdc++.h>
using namespace std;
int n, a[100100], l[100100], b[100100], seen[100100], sz[100100], q;
double p[100100];
vector<int> g[100100];
void dfs(int u) {
  seen[u] = 1;
  sz[u] = 1;
  for (int v : g[u]) {
    if (not seen[v]) {
      dfs(v);
      sz[u] += sz[v];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i] >> l[i];
    --a[i];
    --b[i];
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  memset(seen, 0, sizeof seen);
  dfs(0);
  double len = 0.0;
  for (int i = 0; i < n - 1; i++) {
    double s = (double)min(sz[a[i]], sz[b[i]]);
    p[i] = (2 * (s * (n - s))) / (n * (n - 1.0));
    len += l[i] * p[i] * 3.0;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int id, newl;
    cin >> id >> newl;
    id--;
    len -= l[id] * p[id] * 3.0;
    l[id] = newl;
    len += l[id] * p[id] * 3.0;
    cout << len << "\n";
  }
}
