#include <bits/stdc++.h>
using namespace std;
int ans[100009];
typedef struct x {
  int no_of_nodes;
  int color;
} Vertices;
typedef struct y {
  int u;
  int v;
  long long int x;
  long long int coun;
  long long int val;
} Edges;
Vertices vertices[100009];
Edges edges[100009];
vector<int> vec1[100009];
map<pair<int, int>, int> where;
void DFS(int v) {
  vertices[v].no_of_nodes = 1;
  vertices[v].color = 1;
  for (int i = 0; i < vec1[v].size(); i++) {
    if (vertices[vec1[v][i]].color == 0) {
      DFS(vec1[v][i]);
      vertices[v].no_of_nodes += vertices[vec1[v][i]].no_of_nodes;
      int ind = where[make_pair(v, vec1[v][i])];
      edges[ind].x = vertices[vec1[v][i]].no_of_nodes;
    }
  }
  vertices[v].color = 2;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    vertices[i].color = 0;
    vec1[i].clear();
  }
  for (int i = 1; i < n; i++) {
    cin >> edges[i].u >> edges[i].v >> edges[i].val;
    vec1[edges[i].u].push_back(edges[i].v);
    vec1[edges[i].v].push_back(edges[i].u);
    where[make_pair(edges[i].u, edges[i].v)] = i;
    where[make_pair(edges[i].v, edges[i].u)] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (vertices[i].color == 0) {
      DFS(i);
    }
  }
  for (int i = 1; i < n; i++) edges[i].coun = edges[i].x * (n - edges[i].x);
  long long int ans = 0;
  for (int i = 1; i < n; i++) ans += edges[i].coun * edges[i].val;
  double den = (double)(n - 1) * n / 6;
  int queries;
  cin >> queries;
  while (queries--) {
    int ind;
    long long int p;
    cin >> ind >> p;
    ans -= (edges[ind].val - p) * edges[ind].coun;
    edges[ind].val = p;
    double tmp = (double)ans;
    tmp /= den;
    printf("%.12lf\n", tmp);
  }
}
