#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 5;
vector<int> l[nmax];
bool viz[nmax];
long long d[nmax];
long long nr[nmax];
double prob[nmax];
struct Edge {
  long long x, y, l;
};
vector<Edge> v;
void dfs(int nod, int t) {
  nr[nod] = 1;
  d[nod] = d[t] + 1;
  viz[nod] = 1;
  for (auto x : l[nod])
    if (!viz[x]) {
      dfs(x, nod);
      nr[nod] += nr[x];
    }
}
int main() {
  long long n, a, b, le;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a >> b >> le;
    v.push_back({a, b, le});
    l[a].push_back(b);
    l[b].push_back(a);
  }
  dfs(1, 0);
  double s = 0.0;
  for (int i = 0; i < n - 1; i++) {
    int a = v[i].x, b = v[i].y, c = v[i].l;
    if (d[a] < d[b]) swap(a, b);
    double p1 = 1.0 * (nr[a] * (n - nr[a]));
    double p2 = 0.5 * ((n - 1) * n);
    prob[i] = p1 / p2;
    s += prob[i] * c;
  }
  int q;
  cin >> q;
  while (q--) {
    cin >> a >> b;
    s -= prob[a - 1] * v[a - 1].l;
    s += prob[a - 1] * b;
    v[a - 1].l = b;
    cout << fixed << setprecision(6) << 3.0 * s << "\n";
  }
}
