#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 10;
int w[maxn];
struct Edge {
  int u, v, c;
  Edge(int u, int v, int c) : u(u), v(v), c(c) {}
};
vector<Edge> edges;
vector<int> g[maxn];
void add(int u, int v, int c) {
  edges.push_back(Edge(u, v, c));
  edges.push_back(Edge(v, u, c));
  int m = edges.size();
  g[u].push_back(m - 2);
  g[v].push_back(m - 1);
}
double dis[maxn], dis2[maxn];
int num[maxn];
int dist[maxn];
int n;
void dfs(int u, int fa) {
  num[u] = 1;
  for (int i = 0; i < ((int)((g[u]).size())); i++) {
    Edge e = edges[g[u][i]];
    int v = e.v;
    int c = e.c;
    if (v == fa) continue;
    dist[v] = dist[u] + c;
    dfs(v, u);
    num[u] += num[v];
    dis[u] += 0LL + dis[v] + 1LL * c * num[v];
  }
}
void dfs2(int u, int fa) {
  for (int i = 0; i < ((int)((g[u]).size())); i++) {
    Edge e = edges[g[u][i]];
    int v = e.v;
    int c = e.c;
    if (v == fa) continue;
    dis2[v] = 0LL + dis[u] - dis[v] - 1LL * c * num[v] + dis2[u] +
              1LL * c * (n - num[v]);
    dfs2(v, u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, w + i);
    c = w[i];
    add(u, v, c);
  }
  dfs(1, 0);
  dfs2(1, 0);
  double tmp = 0, m = 1.0 * n * (n - 1) * (n - 2) / 6;
  for (int i = 1; i <= n; i++) {
    tmp += dis[i] + dis2[i];
  }
  tmp /= 2;
  tmp *= (n - 2);
  int q;
  scanf("%d", &q);
  double ans = tmp;
  while (q--) {
    int x, c;
    scanf("%d%d", &x, &c);
    Edge e = edges[(x - 1) << 1];
    int u = e.u;
    int v = e.v;
    if (dist[u] > dist[v]) swap(u, v);
    int delta = w[x] - c;
    w[x] = c;
    ans -= (long double)delta * (n - num[v]) * num[v] * (n - 2);
    printf("%.10f\n", 1.0 * ans / m);
  }
  return 0;
}
