#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 50;
const int maxm = 1e6 + 50;
const double eps = 1e-10;
const int max_index = 62;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
inline int read() {
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x;
}
struct Edge {
  int u, v;
  int w;
} E[maxn];
int son[maxn];
std::vector<int> G[maxn];
void dfs(int u) {
  son[u] = 1;
  for (int &v : G[u]) {
    if (son[v]) continue;
    dfs(v);
    son[u] += son[v];
  }
}
int main() {
  int n = read();
  for (int i = 1; i < n; i++) {
    E[i].u = read(), E[i].v = read(), E[i].w = read();
    G[E[i].u].push_back(E[i].v);
    G[E[i].v].push_back(E[i].u);
  }
  dfs(1);
  double ans = 0;
  for (int i = 1; i < n; i++) {
    int u = E[i].u, v = E[i].v, w = E[i].w;
    if (son[u] < son[v]) swap(u, v);
    ans += 6.0 * w * son[v] * (n - son[v]) / n / (n - 1);
  }
  int q = read();
  while (q--) {
    int x = read(), y = read();
    int u = E[x].u, v = E[x].v, w = E[x].w;
    int d = y - w;
    if (son[u] < son[v]) swap(u, v);
    ans += 6.0 * d * son[v] * (n - son[v]) / n / (n - 1);
    E[x].w = y;
    printf("%.10f\n", ans);
  }
  return 0;
}
