#include <bits/stdc++.h>
using namespace std;
int x, y, n, m, z[100001];
int64_t s, u[100001];
vector<pair<int, int> > a[100001];
int64_t f(int i, int p, int z) {
  int64_t r = 1;
  for (auto e : a[i]) {
    if (e.first == p) continue;
    r += f(e.first, i, e.second);
  }
  u[z] = r * (n - r);
  return r;
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> x >> y >> z[i];
    a[x].emplace_back(y, i);
    a[y].emplace_back(x, i);
  }
  f(1, 0, 0);
  cin >> m;
  for (int i = 1; i < n; i++) s += z[i] * u[i];
  cout << setprecision(6) << fixed;
  while (m--) {
    cin >> x >> y;
    s += (y - z[x]) * u[x];
    z[x] = y;
    cout << (double(6) * double(s) / double(n) / double(n - 1)) << "\n";
  }
  return 0;
}
