Crazy Shopping

Time Limit: 3 Seconds
Memory Limit: 65536 KB

Because of the 90th anniversary of the *Coherent & Cute Patchouli* (C.C.P), *Kawashiro Nitori* decides to buy a lot of rare things to celebrate.

*Kawashiro Nitori* is a very shy *kappa* (a type of water sprite that live in rivers) and she lives on *Youkai Mountain*. *Youkai Mountain* is a dangerous place full of *Youkai*, so normally humans are unable to be close to the mountain. But because of the financial crisis, something have changed. For example, *Youkai Mountain* becomes available for tourists.

On the mountain there are `N` tourist attractions, and there is a shop in each tourist attraction. To make the tourists feel more challenging (for example, to collect all kinds of souvenirs), each shop sells only one specific kind of souvenir that can not buy in any other shops. Meanwhile, the number of the souvenirs which sells in each shop is infinite. *Nitori* also knows that each kind of souvenir has a weight `TW`_{i} (in kilogram) and a value `TV`_{i}.

Now *Nitori* is ready to buy souvenirs. For convenience, *Nitori* numbered the tourist attraction from 1 to `N`. At the beginning *Nitori* is located at the tourist attraction `X` and there are `M` roads connect some pairs of tourist attractions, and each road has a length `L`. However, because *Youkai Mountain* is very steep, all roads are uni-directional. By the way, for same strange reason, the roads ensure that when someone left one tourist attraction, he can not arrive at the same tourist attraction again if he goes along the road.

*Nitori* has one bag and the maximal load is `W` kilogram. When there are `K` kilogram things in *Nitori*'s bag, she needs to cost `K` units energy for walking one unit length road. Of course she doesn't want to waste too much energy, so please calculate the minimal cost of energy of *Nitori* when the value is maximal.

Notice: *Nitori* can buy souvenir at tourist attraction `X`, and she can stop at any tourist attraction. Also, there are no two different roads between the same two tourist attractions. Moreover, though the shop sells different souvenirs, it is still possible for two different kinds of souvenir have the same weight or value.

#### Input

There are multiple test cases. For each test case:

The first line contains four numbers `N` (1 <= `N` <= 600) - the number of tourist attractions, `M` (1 <= `M` <= 60000) - the number of roads, `W` (1 <= `W` <= 2000) - the load of the bag and `X` (1 <= `X` <= `N`) - the starting point of *Nitori*.

Then followed by `N` lines, each line contains two integers which means the shop on tourist attraction `i` sells the `TW`_{i} and `TV`_{i} things (1 <= `TW`_{i} <= W, 1 <= `TV`_{i} <= 10000).

Next, there are `M` lines, each line contains three numbers, `X`_{i}, `Y`_{i} and `L`_{i}, which means there is a one-way road from tourist attraction `X`_{i} to `Y`_{i}, and the length is `L`_{i} (1 <= `X`_{i},`Y`_{i} <= N, 1 <= `L`_{i} <= 10000).

#### Output

For each test case, output the answer as the description required.

#### Sample Input

4 4 10 1
1 1
2 3
3 4
4 5
1 2 5
1 3 4
2 4 4
3 4 5

#### Sample Output

0

#### Hint

It's no hard to know that *Nitori* can buy all things at tourist attraction 2, so she cost 0 unit energy.

Author:

**DAI, Longao**
Submit
Status