#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct Edge {
  int to, cost;
  Edge(int t, int c) : to(t), cost(c) {}
  bool operator>(const Edge& rhs) const { return cost > rhs.cost; }
};
long long N, S;
vector<int> dp, parent;
vector<vector<Edge>> G;
void dfs(int par, int node, int d) {
  parent[node] = par;
  dp[node] = 1;
  for (int i = 0; i < int((G[node]).size()); ++i) {
    int& to = G[node][i].to;
    if (to == par) continue;
    dfs(node, to, d + 1);
    dp[node] += dp[to];
    S += 2 * dp[to] * (N - dp[to]) * G[node][i].cost;
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> N;
  G.assign(N + 1, vector<Edge>());
  vector<pair<int, Edge>> edges;
  for (int i = (0); i < (N - 1); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a].push_back(Edge(b, c));
    G[b].push_back(Edge(a, c));
    edges.push_back(make_pair(a, Edge(b, c)));
  }
  dp.assign(N + 1, 0);
  parent.assign(N + 1, -1);
  S = 0;
  dfs(-1, 1, 0);
  int Q;
  cin >> Q;
  while (Q--) {
    int idx, c;
    cin >> idx >> c;
    --idx;
    Edge& e = edges[idx].second;
    int a = edges[idx].first, b = e.to;
    if (parent[b] == a) swap(a, b);
    S -= (e.cost - c) * 2 * dp[a] * (N - dp[a]);
    cout << fixed << setprecision(7) << 3 * S * 1. / (N * (N - 1)) << endl;
    e.cost = c;
  }
  return 0;
}
