#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
vector<vector<pair<int, int>>> graph(MAX_N);
int sz[MAX_N];
int Pr[MAX_N];
long long res;
void dfs(int node, int pr = 0) {
  int sum = 1;
  for (int x = 0; x < graph[node].size(); x++) {
    if (graph[node][x].first != pr) {
      dfs(graph[node][x].first, node);
      sum += sz[graph[node][x].first];
    }
  }
  Pr[node] = pr;
  sz[node] = sum;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int>> edges(n);
  vector<int> cost(n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d %d", &edges[i].first, &edges[i].second, &cost[i]);
    graph[edges[i].first].push_back({edges[i].second, cost[i]});
    graph[edges[i].second].push_back({edges[i].first, cost[i]});
  }
  dfs(1);
  for (int x = 0; x < edges.size(); x++) {
    int u, v;
    u = edges[x].first;
    v = edges[x].second;
    if (u != Pr[v]) swap(u, v);
    int f, s;
    f = sz[v];
    s = sz[1] - f;
    res += 1LL * 2 * cost[x] * f * s;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int Ind, NewVal;
    scanf("%d %d", &Ind, &NewVal);
    Ind--;
    int change = cost[Ind] - NewVal;
    int u = edges[Ind].first;
    int v = edges[Ind].second;
    if (u != Pr[v]) swap(u, v);
    int f, s;
    f = sz[v];
    s = sz[1] - f;
    res -= 1LL * 2 * change * f * s;
    cost[Ind] = NewVal;
    cout << fixed << double(res * 3) / double(1LL * n * (n - 1)) << endl;
  }
}
