#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
inline void gmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
  if (b < a) a = b;
}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,
          ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567,
          ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
void fre() {
  freopen("/Users/luras/Desktop/in.txt", "r", stdin);
  freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const int INF = 1e9;
int casenum, casei;
long long n, x, y;
double ans;
struct A {
  long long x, y, v;
} a[N];
long long c2(long long x) { return x * (x - 1) / 2; }
double c3(double x) { return x * (x - 1) / 6; }
long long num[N], ind[N], m;
vector<pair<int, int> > vc[N];
void dfs(int v, int pre) {
  ind[v] = 1;
  long long cnt = vc[v].size();
  for (int j = 0; j < cnt; j++) {
    int u = vc[v][j].first;
    if (u == pre) {
      continue;
    }
    dfs(u, v);
    ind[v] += ind[u];
    num[vc[v][j].second] = ind[u] * (n - ind[u]);
  }
}
int main() {
  while (~scanf("%lld", &n)) {
    memset(ind, 0, sizeof(ind));
    memset(num, 0, sizeof(num));
    for (int i = 1; i <= n; i++) vc[i].clear();
    for (int i = 1; i < n; i++) {
      scanf("%lld%lld%lld", &a[i].x, &a[i].y, &a[i].v);
      vc[a[i].x].push_back(make_pair(a[i].y, i));
      vc[a[i].y].push_back(make_pair(a[i].x, i));
    }
    dfs(1, 0);
    ans = 0;
    for (int i = 1; i < n; i++) {
      ans += num[i] * a[i].v;
    }
    scanf("%lld", &m);
    for (int i = 1; i <= m; i++) {
      scanf("%lld%lld", &x, &y);
      ans -= (a[x].v - y) * num[x];
      a[x].v = y;
      printf("%.12lf\n", ans / c3(n));
    }
  }
  return 0;
}
