#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int u[maxn], v[maxn], w[maxn];
struct Edge {
  int v, nxt;
  Edge() {}
  Edge(int v, int nxt) : v(v), nxt(nxt) {}
};
int n;
int ecnt;
int head[maxn];
Edge edges[maxn * 2];
void init() {
  ecnt = 0;
  memset(head, -1, sizeof(head));
}
void AddEdge(int u, int v) {
  edges[ecnt] = Edge(v, head[u]);
  head[u] = ecnt++;
}
int fa[maxn], sz[maxn];
void dfs(int u) {
  sz[u] = 1;
  for (int i = head[u]; ~i; i = edges[i].nxt) {
    int v = edges[i].v;
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs(v);
    sz[u] += sz[v];
  }
}
int main() {
  scanf("%d", &n);
  init();
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", u + i, v + i, w + i);
    AddEdge(u[i], v[i]);
    AddEdge(v[i], u[i]);
  }
  fa[1] = 0;
  dfs(1);
  for (int i = 1; i < n; i++)
    if (v[i] == fa[u[i]]) swap(v[i], u[i]);
  double tot = 0;
  for (int i = 1; i < n; i++) tot += (double)w[i] * sz[v[i]] * (n - sz[v[i]]);
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    int t = w[a] - b;
    w[a] = b;
    tot -= (double)t * (sz[v[a]]) * (n - sz[v[a]]);
    printf("%.10lf\n", tot * 6.0 / n / (n - 1));
  }
  return 0;
}
