#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, c;
  Edge() {}
  Edge(int _u, int _v, int _c) {
    u = _u;
    v = _v;
    c = _c;
  }
};
const int maxN = 1e5 + 5;
int n;
vector<int> head[maxN];
Edge e[maxN];
int d[maxN];
inline void DFS(int u, int pre) {
  d[u] = 1;
  for (int i = 0; i < (int)head[u].size(); ++i) {
    int v = head[u][i];
    if (v == pre) continue;
    DFS(v, u);
    d[u] += d[v];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    head[u].push_back(v);
    head[v].push_back(u);
    e[i] = Edge(u, v, c);
  }
  DFS(1, 0);
  long long sum = 0;
  for (int i = 1; i <= n - 1; ++i) {
    int v = min(d[e[i].u], d[e[i].v]);
    sum += (long long)v * (n - v) * e[i].c;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int i, x;
    scanf("%d%d", &i, &x);
    int v = min(d[e[i].u], d[e[i].v]);
    sum -= (long long)v * (n - v) * e[i].c;
    sum += (long long)v * (n - v) * x;
    e[i].c = x;
    printf("%.9lf\n", 6.0 * sum / ((long long)n * (n - 1)));
  }
  return 0;
}
