#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x > y ? y : x;
}
const int INF = (1ll << 30);
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = 0;
  } while (ch > '9' || ch < '0');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  x = f ? x : -x;
}
template <typename T>
void write(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const long long N = 1e5 + 7;
long long n, m, E, sz[N], V[N], head[N], weight[N];
double f[N];
struct EDGE {
  long long id, w, to, nxt;
} edge[N << 1];
inline void addedge(long long u, long long v, long long w, long long i) {
  edge[++E].to = v;
  edge[E].nxt = head[u];
  edge[E].w = w;
  edge[E].id = i;
  head[u] = E;
}
inline void dfs(long long u, long long f) {
  sz[u] = 1;
  for (long long i = head[u]; i; i = edge[i].nxt) {
    long long v = edge[i].to, w = edge[i].w;
    if (v == f) continue;
    dfs(v, u);
    V[edge[i].id] = v;
    weight[v] = w;
    sz[u] += sz[v];
  }
}
signed main() {
  read(n);
  for (long long i = 1, u, v, w; i < n; i++) {
    read(u);
    read(v);
    read(w);
    addedge(u, v, w, i);
    addedge(v, u, w, i);
  }
  dfs(1, 0);
  for (long long i = 1; i <= n; i++) {
    if (sz[i] >= 2 && n - sz[i] >= 1)
      f[i] += sz[i] * (sz[i] - 1) / 2 * (n - sz[i]);
    if (n - sz[i] >= 2) f[i] += (n - sz[i]) * (n - sz[i] - 1) / 2 * sz[i];
  }
  double ans = 0, tmp = 1ll * n * (n - 1) / 2 * (n - 2) / 3;
  for (long long i = 1; i <= n; i++) ans += 2.0 * f[i] * weight[i];
  read(m);
  for (long long i = 1, x, y; i <= m; i++) {
    read(x);
    read(y);
    ans -= 2 * (weight[V[x]] - y) * f[V[x]];
    weight[V[x]] = y;
    printf("%.6lf\n", 1.0 * ans / tmp);
  }
  return 0;
}
