#include <bits/stdc++.h>
using namespace std;
long long n;
long long onsides[100005];
long long subtree[100005];
long long len[100005];
vector<pair<long long, long long> > graph[100005];
long long visited[100005];
void dfs(long long x) {
  visited[x] = true;
  subtree[x] = 1;
  for (long long i = 0; i < graph[x].size(); ++i) {
    if (!visited[graph[x][i].first]) {
      dfs(graph[x][i].first);
      subtree[x] += subtree[graph[x][i].first];
      onsides[graph[x][i].second] =
          (n - subtree[graph[x][i].first]) * subtree[graph[x][i].first];
    }
  }
}
int main() {
  long long total = 0;
  for (long long i = 0; i < 100005; ++i) visited[i] = false;
  cin >> n;
  for (long long x = 0; x < n - 1; ++x) {
    long long i, j, k;
    cin >> i >> j >> k;
    i--;
    j--;
    graph[i].push_back(pair<long long, long long>(j, x));
    graph[j].push_back(pair<long long, long long>(i, x));
    len[x] = k;
  }
  dfs(0);
  long long q;
  cin >> q;
  for (long long i = 0; i < n - 1; ++i) {
    total += len[i] * onsides[i];
  }
  for (long long i = 0; i < q; ++i) {
    long long x, l;
    cin >> x >> l;
    x--;
    total -= (len[x] - l) * onsides[x];
    len[x] = l;
    cout << fixed << setprecision(6)
         << (double)total / (double)((n) * (n - 1)) * 6.000000 << "\n";
  }
}
