#include <bits/stdc++.h>
using namespace std;
class C_ {};
template <typename T>
C_& operator<<(C_& __m, const T& __s) {
  if (!1) cerr << "\E[91m" << __s << "\E[0m";
  return __m;
}
C_ merr;
struct __s {
  __s() {
    if (1) {
      ios_base::Init i;
      cin.sync_with_stdio(0);
      cin.tie(0);
    }
  }
  ~__s() {
    merr << "Execution time: " << (double)clock() / CLOCKS_PER_SEC << " s.\n";
  }
} __S;
vector<pair<int, int> > G[111111];
long long cnt[111111];
long long L[111111];
bool u[111111];
int n;
long double ans;
void dfs(int v, int len) {
  u[v] = 1;
  cnt[v] = 1;
  L[v] = len;
  for (int i = 0; i < (int)G[v].size(); i++) {
    int vv = G[v][i].first, ww = G[v][i].second;
    if (u[vv]) continue;
    dfs(vv, len + ww);
    cnt[v] += cnt[vv];
    ans += ww * cnt[vv] * (n - cnt[vv]) * (n - 2);
  }
}
struct p {
  int a, b, w;
  p(int aa = 0, int bb = 0, int ww = 0) { a = aa, b = bb, w = ww; }
};
int main() {
  int q;
  vector<p> E;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    G[a].push_back(make_pair(b, w));
    G[b].push_back(make_pair(a, w));
    E.push_back(p(a, b, w));
  }
  dfs(1, 0);
  cin >> q;
  for (int i = 0; i < q; i++) {
    int e, w, a, b, ow;
    cin >> e >> w;
    e--;
    a = E[e].a;
    b = E[e].b;
    ow = E[e].w;
    if (L[a] < L[b]) {
      ans += (w - ow) * cnt[b] * (n - cnt[b]) * (n - 2);
    } else {
      ans += (w - ow) * cnt[a] * (n - cnt[a]) * (n - 2);
    }
    E[e].w = w;
    cout << fixed << setprecision(10)
         << ans * 6.0L / (n * 1.0L * (n - 1) * (n - 2)) << '\n';
  }
  return 0;
}
