Bond

题目背景

重题请做P1967

题目描述

[problemUrl]: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=25&page=show_problem&problem=2339 [PDF](https://uva.onlinejudge.org/external/113/p11354.pdf) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA11354/cb60f7c8e7c215e8be912d72cce4907aa905240a.png)

输入输出格式

输入格式


![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA11354/1b7c4bc87a8fb136d997d14d3f627ef5c72f51b2.png)

输出格式


![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA11354/0dd2bd937e600b451e36636738255d554d14383b.png)

输入输出样例

输入样例 #1

4 5
1 2 10
1 3 20
1 4 100
2 4 30
3 4 10
2
1 4
4 1
2 1
1 2 100
1
1 2

输出样例 #1

20
20

100