#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
struct edge {
  long long to, wt, id;
  edge(long long t, long long w, long long i) : to(t), wt(w), id(i) {}
};
long long wt[100010];
long long roads[100010];
long long cnt[100010];
vector<edge> adj[100010];
long double total;
long long dfs1(long long cur, long long par = -1) {
  cnt[cur] = 1;
  for (int i = 0; i < (int)(((int)adj[cur].size())); ++i) {
    if (par == adj[cur][i].to) continue;
    cnt[cur] += dfs1(adj[cur][i].to, cur);
  }
  return cnt[cur];
}
long long n;
void dfs2(long long cur, long long par = -1, long long id = -1,
          long long w = -1) {
  if (id != -1) {
    long long above = n - cnt[cur];
    long long below = cnt[cur];
    roads[id] =
        (above * (above - 1) / 2 * below + below * (below - 1) / 2 * above) *
        (3 * 2 * 2);
    total += roads[id] * w;
  }
  for (int i = 0; i < (int)(((int)adj[cur].size())); ++i) {
    if (par == adj[cur][i].to) continue;
    dfs2(adj[cur][i].to, cur, adj[cur][i].id, adj[cur][i].wt);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  long long a, b, c;
  for (int i = 0; i < (int)(n - 1); ++i) {
    cin >> a >> b >> c;
    adj[a].push_back(edge(b, c, i + 1));
    adj[b].push_back(edge(a, c, i + 1));
    wt[i + 1] = c;
  }
  dfs1(1);
  dfs2(1);
  long long ways = n * (n - 1) * (n - 2);
  long long q;
  long long r, w;
  cin >> q;
  for (int i = 0; i < (int)(q); ++i) {
    cin >> r >> w;
    total -= roads[r] * (wt[r] - w);
    wt[r] = w;
    cout << fixed << setprecision(9) << double(total) / ways << endl;
  }
  return 0;
}
