M. Web Delivery
time limit per test
1 second
memory limit per test
960 megabytes
input
standard input
output
standard output
Example
Input
2
3 5
1 3 5 7 9
5 7 9 1 3
9 1 3 5 7
4 3 2 3 4
4 3
1 2 4
2 3 1
4 1 2
3 2 1
2 4 4
Output
11
11