#P10977. [2015杭电多校]Travel with candy

[2015杭电多校]Travel with candy

Travel with candy

Problem Description

There are n+1 cities on a line. They are labeled from city 0 to city n. Mph has to start his travel from city 0, passing city 1,2,3...n-1 in order and finally arrive city n. The distance between city i and city 0 is aia_i. Mph loves candies and when he travels one unit of distance, he should eat one unit of candy. Luckily, there are candy shops in the city and there are infinite candies in these shops. The price of buying and selling candies in city i is buyibuy_i and sellisell_i per unit respectively. Mph can carry at most C unit of candies. Now, Mph want you to calculate the minimum cost in his travel plan.

Input

There are multiple test cases. The first line has a number T, representing the number of test cases. For each test : The first line contains two numbers NN and CC (N2×105,C106)(N \leq 2\times 10^5, C\leq 10^6) The second line contains NN numbers a1,a2,...,ana_1,a_2,...,a_n. It is guaranteed that ai>ai1a_i>a_{i-1} for each 1<i<=N 1< i<=N . Next N+1N+1 line : the i-th line contains two numbers buyi1buy_{i-1} and selli1sell_{i-1} respectively. (selli1buyi1106sell_{i-1} \leq buy_{i-1} \leq 10^6) The sum of NN in each test is less than 3×1053\times 10^5.

Output

Each test case outputs a single number representing your answer.(Note: the answer can be a negative number)

Sample Input

1
4 9
6 7 13 18
10 7
8 4
3 2
5 4
5 4

Sample Output

105

Author

SXYZ

Source

2015 Multi-University Training Contest 8