#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vpii = vector<pair<int, int> >;
using vpll = vector<pair<long long, long long> >;
using vld = vector<long double>;
using vb = vector<bool>;
using vd = vector<double>;
const int inf = (int)1e9 + 7;
const long long llinf = (long long)1e18 + 7;
long long n;
vll a, b, l;
vll d, sbs, vis;
vd p;
vvll adj;
long long dfs(long long s, long long depth) {
  vis[s] = 1;
  d[s] = depth;
  for (auto i : adj[s]) {
    if (!vis[i]) {
      sbs[s] += dfs(i, depth + 1);
    }
  }
  sbs[s] += 1;
  return sbs[s];
}
void solve() {
  cout << fixed << setprecision(7);
  cin >> n;
  adj.resize(n + 1);
  d.resize(n + 1);
  sbs.resize(n + 1, 0);
  vis.resize(n + 1, 0);
  p.resize(n + 1);
  for (long long i = 0; i < n - 1; i++) {
    long long p, q, r;
    cin >> p >> q >> r;
    adj[p].push_back(q);
    adj[q].push_back(p);
    a.push_back(p);
    b.push_back(q);
    l.push_back(r);
  }
  long long o = dfs(1, 0);
  double ex = 0;
  for (long long i = 0; i < n - 1; i++) {
    double n1 = (d[a[i]] > d[b[i]]) ? sbs[a[i]] : sbs[b[i]];
    double n2 = n - n1;
    p[i] = 2 * (n1 * n2 * 1.0) / (n * (n - 1));
    ex += l[i] * p[i];
  }
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long r, w;
    cin >> r >> w;
    ex += (w - l[r - 1]) * (p[r - 1]);
    cout << 3 * ex << "\n";
    l[r - 1] = w;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long ttt = 1;
  for (long long i = 1; i <= ttt; i++) {
    solve();
  }
}
