#include <bits/stdc++.h>
int n, k, l[300000], val[300000], next[300000], cost[300000], lista[300000],
    s[300000], t[300000], e[300000];
long long ans, r[300000];
inline void adauga(int x, int y, int z) {
  k++;
  val[k] = y;
  next[k] = lista[x];
  cost[k] = z;
  lista[x] = k;
}
void dfs(int x) {
  int p = lista[x];
  s[x] = 1;
  while (p) {
    if (t[x] == val[p]) {
      e[x] = (p + 1) / 2;
      l[e[x]] = cost[p];
    } else {
      t[val[p]] = x;
      dfs(val[p]);
      s[x] += s[val[p]];
    }
    p = next[p];
  }
  r[e[x]] = s[x] * (long long)(n - s[x]);
  ans += r[e[x]] * l[e[x]];
}
int main() {
  int i, x, y, z, q;
  long long cat;
  fscanf(stdin, "%d", &n);
  for (i = 1; i < n; i++) {
    fscanf(stdin, "%d%d%d", &x, &y, &z);
    adauga(x, y, z);
    adauga(y, x, z);
  }
  dfs(1);
  cat = n * (long long)(n - 1);
  for (fscanf(stdin, "%d", &q); q; q--) {
    fscanf(stdin, "%d%d", &x, &y);
    ans -= r[x] * l[x];
    l[x] = y;
    ans += r[x] * l[x];
    fprintf(stdout, "%lf\n", (6 * ans) / (double)cat);
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
