#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e5 + 10;
int n;
int x[SIZE], y[SIZE], v[SIZE], h[SIZE], num[SIZE];
vector<pair<int, int> > e[SIZE];
long long sum[SIZE];
long long all = 0;
void dfs1(int x, int lt, int v) {
  h[x] = v;
  num[x] = 1;
  for (int i = 0; i < (((int)(e[x]).size())); ++i) {
    int y = e[x][i].first;
    if (y == lt) continue;
    dfs1(y, x, v + 1);
    num[x] += num[y];
    all += (long long)num[y] * (n - num[y]) * e[x][i].second;
  }
}
int main() {
  scanf("%d", &(n));
  for (int i = (1); i < (n); ++i) {
    scanf("%d%d%d", &(x[i]), &(y[i]), &(v[i]));
    e[x[i]].push_back(make_pair(y[i], v[i]));
    e[y[i]].push_back(make_pair(x[i], v[i]));
  }
  dfs1(1, 1, 0);
  int(Q);
  scanf("%d", &Q);
  while (Q--) {
    int id, u;
    scanf("%d%d", &id, &u);
    int low;
    if (h[x[id]] < h[y[id]])
      low = y[id];
    else
      low = x[id];
    all -= (long long)num[low] * (n - num[low]) * (v[id] - u);
    v[id] = u;
    printf("%.9f\n", all * 6. / (n * (n - 1LL)));
  }
  return 0;
}
