Time limit per test: 2.75 second(s) Memory limit: 262144 kilobytes
input: standard output: standard
Everybody knows about the problems with roads in Berland. The government has been trying to undertake major repairs for many years, but the roads have never been repaired due to the lack of money in the budget.
There are n cities and m roads in Berland. The cities are numbered from 1 to n. The roads are numbered from 1 to m. Each road connects a pair of different cities, all the roads are two-way. There is at most one road between any pair of cities. The cost of repairing is known for each road.
Clearly, repairing all roads in Berland is an unaffordable luxury, so the government decided to repair only such set of the roads, that it's possible to get from any city to any other city by the roads from this repaired set, and the total cost of these road works is minimal.
In the circumstances of the global economic crisis and global warming, road repair costs change every day. Berland's scientists managed to predict these changes, concluding that the cost of road works will change for only one road each day. They created a full list of expected changes for the coming t days — for each day they came up a road and its new repair cost.
The government of Berland would like to know when it would be better to repair the roads, so they need to figure out the cost of road works for every of the coming t days before making a final decision. Your task is to help them and figure out the total repair cost of Berland's road system at the end of each these t days. As repair costs change over time, the set of selected roads can change on a daily basis as well.
Input
The first line contains a pair of integers n,m (2 ≤ n ≤ 40000, n - 1 ≤ m ≤ 40000), where n — the amount of cities, m — the amount of roads. Each of the following m lines contains a road description: three integer numbers xi, yi and pi (1 ≤ xi, yi ≤ n, xi ≠ yi, 1 ≤ pi ≤ 40000), where xi and yi are indices of the cities connected by the given road, and pi — initial cost of repairing it.
Then there follows a line with the only number t (1 ≤ t ≤ 40000), t — amount of days. The following t lines contain the scientists' predictions for the coming t days. Each of t lines contains a pair of integer numbers ei, ci (1 ≤ ei ≤ m, 1 ≤ ci ≤ 40000), where ci — is the new repair cost for the road ei.
It's possible to get from any city to any other city by the roads. The cost of repair for a single road can be changed more than once over time.
Output
Output t lines, each of them should contain the road system's total repair cost at the end of each day.