#include <bits/stdc++.h>
using namespace std;
template <typename T>
void smax(T &a, T b) {
  if (a < b) a = b;
}
const double EPS = 1e-9;
vector<pair<pair<int, int>, int> > adj[100000 + 10];
long long totSum;
pair<pair<int, int>, int> edges[100000 + 10];
int belows[100000 + 10];
int n;
pair<long long, int> f(int u, int jad) {
  long long sum = 0;
  int cnts = 0;
  for (int i = 0; i < ((int)(adj[u]).size()); ++i) {
    int v = adj[u][i].first.first;
    int cost = adj[u][i].first.second;
    int edge = adj[u][i].second;
    if (v == jad) {
      continue;
    }
    pair<long long, int> temp = f(v, u);
    int cnt = temp.second;
    long long belowSum = temp.first + (long long)cost * cnt;
    belows[edge] = cnt;
    totSum += cnt * sum;
    totSum += cnts * belowSum;
    sum += belowSum;
    cnts += cnt;
  }
  cnts++;
  totSum += sum;
  return make_pair(sum, cnts);
}
inline long long getDollarBabe(long long temp) { return temp * (n - temp); }
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v, len;
    cin >> u >> v >> len;
    if (u > v) {
      swap(u, v);
    }
    u--;
    v--;
    adj[u].push_back(make_pair(make_pair(v, len), i));
    adj[v].push_back(make_pair(make_pair(u, len), i));
    edges[i] = make_pair(make_pair(u, v), len);
  }
  totSum = 0;
  f(0, -1);
  int q;
  cin >> q;
  while (q--) {
    int r, w;
    cin >> r >> w;
    r--;
    int temp = belows[r];
    totSum -= (edges[r].second - w) * getDollarBabe(temp);
    edges[r].second = w;
    cout << fixed << setprecision(8)
         << (double)totSum * 6 / ((long long)(n) * (n - 1)) << endl;
  }
  return 0;
}
