#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int w[N];
bool vis[N];
int A[N], B[N];
vector<pair<int, int> > adj[N];
int dfs(int u) {
  vis[u] = true;
  int c = 1;
  for (int j = 0; j < (int)adj[u].size(); ++j) {
    pair<int, int> where = adj[u][j];
    if (!vis[where.first]) {
      A[where.second] = dfs(where.first);
      c += A[where.second];
    }
  }
  return c;
}
int main() {
  int n, x, y;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d %d %d", &x, &y, &w[i]);
    x--;
    y--;
    adj[x].push_back(pair<int, int>(y, i));
    adj[y].push_back(pair<int, int>(x, i));
  }
  dfs(0);
  for (int i = 0; i < n - 1; ++i) {
    B[i] = n - A[i];
  }
  double res = 0;
  for (int i = 0; i < n - 1; ++i) {
    res +=
        ((double)A[i] * (A[i] - 1) * B[i] + (double)B[i] * (B[i] - 1) * A[i]) *
        (double)w[i];
  }
  int q, v;
  cin >> q;
  while (q--) {
    scanf("%d %d", &x, &v);
    x--;
    int delta = w[x] - v;
    w[x] = v;
    res -=
        ((double)A[x] * (A[x] - 1) * B[x] + (double)B[x] * (B[x] - 1) * A[x]) *
        (double)delta;
    printf("%.16f\n", 6.0 * res / n / (n - 1) / (n - 2));
  }
  return 0;
}
