#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int n;
vector<int> g[maxn];
int siz[maxn];
int dep[maxn];
void dfs(int at, int p) {
  siz[at] = 1;
  for (int to : g[at]) {
    if (to == p) continue;
    dep[to] = 1 + dep[at];
    dfs(to, at);
    siz[at] += siz[to];
  }
}
double contrib[maxn];
double sum = 0;
pair<int, pair<int, int>> edges[maxn];
double calc(int u, int v, ll w) {
  if (dep[u] < dep[v]) swap(u, v);
  ll below = siz[u];
  ll above = n - siz[u];
  ll resu = ((1ll * below * (below - 1) / 2) * above) * 2;
  ll resv = (1ll * below * (above * (above - 1) / 2)) * 2;
  return 1.0 * (resu + resv) * w;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b, l;
    cin >> a >> b >> l;
    edges[i] = {l, {a, b}};
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 0);
  for (int i = 0; i < n - 1; i++) {
    int u = edges[i].second.first;
    int v = edges[i].second.second;
    contrib[i] = calc(u, v, edges[i].first);
    sum += contrib[i];
  }
  double den = 1ll * n * (n - 1) * (n - 2) / 6;
  int q;
  cin >> q;
  while (q--) {
    int id, w;
    cin >> id >> w;
    --id;
    int u = edges[id].second.first;
    int v = edges[id].second.second;
    sum -= contrib[id];
    edges[id].first = w;
    contrib[id] = calc(u, v, w);
    sum += contrib[id];
    double res = sum / den;
    cout << res << "\n";
  }
  return 0;
}
