#include <bits/stdc++.h>
using namespace std;
const int Maxn = ((int)1e5) + 100;
struct Edge {
  int u, v;
  long long w;
  Edge() {}
  Edge(int u, int v, int w) : u(u), v(v), w(w) {}
  int getAdj(int x) { return x == u ? v : u; }
};
Edge E[Maxn];
vector<int> g[Maxn];
long long n, num[Maxn], tot;
double base;
long long dfs(int now, int fa) {
  num[now] = 1;
  int sz = g[now].size();
  for (int(i) = (0); (i) <= (sz - 1); ++(i)) {
    Edge& e = E[g[now][i]];
    int u = e.getAdj(now);
    if (u != fa) {
      num[now] += dfs(u, now);
      tot += e.w * 1ll * num[u] * (n - num[u]);
    }
  }
  return num[now];
}
void init() {
  tot = 0;
  base = 6.0 / (n * (n - 1));
  memset(num, 0, sizeof(num));
  dfs(1, -1);
}
double update(int e_idx, long long w) {
  Edge& e = E[e_idx];
  long long d = w - e.w;
  long long t = num[e.u];
  if (num[e.u] > num[e.v]) t = num[e.v];
  tot += t * (n - t) * d;
  e.w = w;
  return tot * base;
}
int main() {
  iostream::sync_with_stdio(false);
  cin >> n;
  for (int(i) = (1); (i) <= (n - 1); ++(i)) {
    int a, b, c;
    cin >> a >> b >> c;
    E[i] = Edge(a, b, c);
    g[a].push_back(i);
    g[b].push_back(i);
  }
  init();
  int q;
  cin >> q;
  cout.setf(ios::fixed, ios::floatfield);
  for (int(i) = (1); (i) <= (q); ++(i)) {
    int r;
    long long w;
    cin >> r >> w;
    cout << std::setprecision(10) << update(r, w) << endl;
  }
  return 0;
}
