#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
void setbit(T& v, int position) {
  v |= (T)1 << position;
}
template <class T>
void unsetbit(T& v, int position) {
  v &= ~((T)1 << position);
}
template <class T>
void togglebit(T& v, int position) {
  v ^= (T)1 << position;
}
template <class T>
bool isbit(T v, int position) {
  return (v & ((T)1 << position)) != 0;
}
template <class T>
inline int countbit(T n) {
  return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));
}
string ReadToEndLine(istream& s) {
  string sLine;
  getline(s, sLine);
  return sLine;
}
char gStr[1024];
struct Runner {
  Runner(istream& in, ostream& out) : mIn(in), mOut(out) {}
  void Run();
  istream& mIn;
  ostream& mOut;
};
struct Node {
  int cnt;
  vector<pair<int, int>> C;
};
vector<int> Roads;
vector<double> E;
vector<double> P;
vector<Node*> Nodes;
int build(int cur, int p) {
  Node* node = Nodes[cur];
  node->cnt = 1;
  for (int i = (0); i < ((int)(node->C.size())); i++) {
    if (node->C[i].first == p) continue;
    node->cnt += build(node->C[i].first, cur);
  }
  return node->cnt;
}
double calcP(double V, double N) {
  return (1. -
          ((V - 2.) * (V - 1.) * V + (N - V - 2.) * (N - V - 1.) * (N - V)) /
              ((N - 2.) * (N - 1.) * N));
}
void calc(int cur, int p, int cntP) {
  Node* node = Nodes[cur];
  for (int i = (0); i < ((int)(node->C.size())); i++) {
    if (node->C[i].first == p) continue;
    int road = node->C[i].second;
    P[road] = 2.0 * calcP(Nodes[node->C[i].first]->cnt, ((int)(Nodes.size())));
    E[road] = Roads[road] * P[road];
    calc(node->C[i].first, cur, 0);
  }
}
void Runner::Run() {
  int N;
  mIn >> N;
  Nodes.resize(N);
  for (int i = (0); i < (N); i++) {
    Nodes[i] = new Node();
  }
  Roads.resize(N - 1);
  for (int i = (0); i < (N - 1); i++) {
    int a, b, l;
    mIn >> a >> b >> l;
    --a;
    --b;
    Nodes[a]->C.push_back(make_pair(b, i));
    Nodes[b]->C.push_back(make_pair(a, i));
    Roads[i] = l;
  }
  build(0, -1);
  E.resize(N - 1, 0.);
  P.resize(N - 1, 0.);
  calc(0, -1, 0);
  double sum = accumulate(E.begin(), E.end(), 0.);
  int Q;
  mIn >> Q;
  for (int q = (0); q < (Q); q++) {
    int r, w;
    mIn >> r >> w;
    --r;
    sum -= E[r];
    Roads[r] = w;
    E[r] = P[r] * w;
    sum += E[r];
    mOut << setprecision(7) << sum << endl;
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  Runner runner(cin, cout);
  runner.Run();
  return 0;
}
