#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > nodes[100010];
int children[100010];
int weights[100010];
int done[100110];
pair<int, int> edge_lr[100010];
int n;
void dfs(int node) {
  done[node] = 1;
  int count = 0;
  for (int i = 0; i < nodes[node].size(); ++i) {
    int next = nodes[node][i].first;
    int edge = nodes[node][i].second;
    if (!done[next]) {
      dfs(next);
      count += children[next] + 1;
      edge_lr[edge].first = children[next] + 1;
      edge_lr[edge].second = n - children[next] - 1;
    }
  }
  children[node] = count;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.precision(30);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a, b, l;
    cin >> a >> b >> l;
    weights[i] = l;
    nodes[a - 1].push_back(pair<int, int>(b - 1, i));
    nodes[b - 1].push_back(pair<int, int>(a - 1, i));
  }
  dfs(0);
  double total_res = 0;
  for (int i = 0; i < n - 1; ++i) {
    long long weight = weights[i];
    int left = edge_lr[i].first;
    int right = edge_lr[i].second;
    total_res += (left * weight * right * 6.0) / n / (n - 1);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int id, w;
    cin >> id >> w;
    --id;
    int weight = weights[id];
    weights[id] = w;
    int left = edge_lr[id].first;
    int right = edge_lr[id].second;
    long long diff = weight - w;
    total_res -= (left * diff * right * 6.0) / n / (n - 1);
    cout << total_res << endl;
  }
  return 0;
}
