#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int M = 5007;
const int inf = 1e9 + 7;
const long long base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;
int pa[N];
int f[N];
vector<pair<int, int> > adj[N];
pair<int, int> id[N];
long long sum = 0;
int n;
void DFS(int u) {
  f[u]++;
  for (int j = 0; j < adj[u].size(); j++) {
    int v = adj[u][j].first;
    int c = adj[u][j].second;
    if (pa[v] == 0) {
      pa[v] = u;
      DFS(v);
      f[u] += f[v];
      sum += (long long)c * f[v] * (n - f[v]);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    if (u > v) swap(u, v);
    adj[u].push_back(make_pair(v, c));
    adj[v].push_back(make_pair(u, c));
    id[i] = make_pair(u, adj[u].size());
  }
  pa[1] = -1;
  DFS(1);
  int m;
  scanf("%d", &m);
  for (int t = 0; t < m; t++) {
    int u, v;
    scanf("%d%d", &u, &v);
    int i = id[u].first, j = id[u].second - 1;
    int tmp = adj[i][j].first;
    int dist = adj[i][j].second - v;
    adj[i][j].second = v;
    if (pa[tmp] == i) i = tmp;
    sum -= (long long)dist * f[i] * (n - f[i]);
    double res = (double)sum * 6 / n / (n - 1);
    printf("%.9lf\n", res);
  }
  return 0;
}
