Book

TimeLimit:10000MS  MemoryLimit:524MB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description

Xzz is a librarian in the reading room whose task is to keep the books in order and disordered books make him feel boring. Two books in wrong order bore him as many as the total pages of two books. Now there are n books that in wrong order. The boredom of Xzz:

In the next m days, the order of the books will be changed by readers. Because Xzz is asked to organize the books for at least one time in the next m days, he wants to know his boredom of each day if he doesn't organize the books. So he would organize books at that day.

Input

First line of the input file contains an integer T(0 < T ≤ 10) that indicates how many cases of inputs are there.

The description of each case is given below:

First line of the input file contains two integers, n and m, indicating the number of books and number of days.

Then follow n lines and each line contains two numbers, ord(i) and vi, indicating that the ith book should be placed in the ai position, and it has vi pages.

Then follow m lines and each line contains two numbers, xj and yj, indicating that the book in position xj will be exchanged with the book in position yj on the jth day.

For all the data: 1 ≤ ord(i), xj, yj ≤ n ≤ 5×10^4 , m ≤ 5×10^4, vi ≤ 10^5

Output

The description of output for each test case is given below:

There should be m lines in total. The i-th line of the output contains one number B, means the boredom B of Xzz if he did not organize books in the first i days.

The result is too big, print the result module 10^9 + 7.

SampleInput
1
5 5
1 1
2 2
3 3
4 4
5 5
1 5
1 5
2 4
5 3
1 3
SampleOutput
42
0
18
28
48
Submit
题目统计信息详细
总AC数1
通过人数1
尝试人数2
总提交量6
AC率16.67%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: