#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1;
int sz[maxn], n;
long long times[maxn], w[maxn];
vector<pair<int, int> > g[maxn];
void dfs(int v, int p = 0) {
  sz[v] = 1;
  for (auto x : g[v]) {
    if (x.first != p) {
      dfs(x.first, v);
      sz[v] += sz[x.first];
    }
  }
  for (auto x : g[v]) {
    if (x.first != p) times[x.second] = 1ll * sz[x.first] * (n - sz[x.first]);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b, l;
    cin >> a >> b >> l;
    g[a].push_back({b, i});
    g[b].push_back({a, i});
    w[i] = l;
  }
  dfs(1);
  long double sum = 0;
  for (int i = 1; i < n; i++) {
    sum += times[i] * w[i];
  }
  int m;
  cin >> m;
  cout << fixed;
  cout.precision(10);
  for (int i = 0; i < m; i++) {
    int t, l;
    cin >> t >> l;
    sum -= times[t] * w[t];
    sum += times[t] * l;
    w[t] = l;
    cout << 6 * sum / n / (n - 1) << '\n';
  }
  return 0;
}
