#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
vector<int> v[MAXN];
int n, m, fa[MAXN], siz[MAXN], x[MAXN], y[MAXN], val[MAXN];
double ans;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
void dfs(int x, int fath) {
  fa[x] = fath;
  siz[x] = 1;
  for (auto y : v[x])
    if (y != fath) dfs(y, x), siz[x] += siz[y];
}
inline double calc(int x, int y) {
  if (fa[y] == x) swap(x, y);
  double sx = siz[x], sy = n - siz[x];
  return ((sy * sx * (sx - 1) / 2) + (sx * sy * (sy - 1) / 2));
}
int main() {
  n = read();
  double tmp = (double)n * (n - 1) * (n - 2) / 6;
  for (int i = 1; i < n; i++) {
    x[i] = read(), y[i] = read(), val[i] = read();
    v[x[i]].push_back(y[i]);
    v[y[i]].push_back(x[i]);
  }
  dfs(1, 0);
  for (int i = 1; i < n; i++) ans += 2 * calc(x[i], y[i]) * val[i];
  m = read();
  for (int i = 1; i <= m; i++) {
    int xx = read(), to = read();
    ans -= 2 * calc(x[xx], y[xx]) * val[xx];
    val[xx] = to;
    ans += 2 * calc(x[xx], y[xx]) * val[xx];
    printf("%.6lf\n", ans / tmp);
  }
  return 0;
}
