#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, v, len;
} edge[100010];
unsigned long long dp[100010];
unsigned long long n;
unsigned long long sum[100010];
vector<pair<int, int> > G[100010];
void dfs(int root, int fa) {
  sum[root] = 1;
  for (int i = 0; i < G[root].size(); i++) {
    int son = G[root][i].first;
    if (son == fa) continue;
    dfs(son, root);
    sum[root] += sum[son];
    dp[G[root][i].second] = sum[son] * (n - sum[son]) * (n - sum[son] - 1LL) +
                            sum[son] * (sum[son] - 1LL) * (n - sum[son]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  int u, v, len;
  for (int i = 1; i < n; i++) {
    cin >> edge[i].u >> edge[i].v >> edge[i].len;
    u = edge[i].u;
    v = edge[i].v;
    G[u].push_back(make_pair(v, i));
    G[v].push_back(make_pair(u, i));
  }
  dfs(1, -1);
  unsigned long long t = 1.0 * (n) * (n - 1) * (n - 2) / 6;
  double tmp = 0;
  for (int i = 1; i < n; i++) {
    tmp += (double)dp[i] * edge[i].len / t;
  }
  int q;
  cin >> q;
  while (q--) {
    cin >> u >> len;
    tmp -= (double)dp[u] * edge[u].len / t;
    edge[u].len = len;
    tmp += (double)dp[u] * edge[u].len / t;
    cout << fixed << setprecision(12) << (double)tmp << endl;
  }
  return 0;
}
