2015
04-14

# Harry Potter and the Present

Hogwarts is welcoming the new term! After Voldemort and the Death Eater were wiped out by Harry Potter and his friends, Harry becomes the glory of the Wizarding World, magician treat him as model, hero, king… and much more than that. So on the ceremony held to signal the beginning of a new school semester, they decide to invite Harry Potter and his three friends: Ginny, Ron and Hermione.
Back to their Alma Mater, Harry and his three friends find a store to purchase some present. They can use at most M units of money, what’s more, they don’t have enough energy to take the presents to Hogwarts if their total weight is exceeding W or the total number is exceeding S. In the store, there are N kinds of present, each of them has price Pi, weight Wi, and value Vi, and as it’s a magical world, any present’s amount is infinite and can be purchased for many times.
Unfortunately, all of them have different idea to buy the gifts. Ginny wants the total number to be the largest, while Ron thinks the more money they cost, the more sincerity there will be shown, Harry wonders the biggest weight they can take because he always likes to challenge himself, Hermione, of course, is already beginning to calculating the biggest value.
Here you see, your task is very simple, calculating the four numbers.

The first line contains a single integer T, indicating the number of test cases.
Each test case begins with four integers N, S, W, M. Then N lines following, each line contains three integers Pi, Wi, Vi, describing a present.

Technical Specification

1. 1 <= T <= 100
2. 1 <= N <= 1 000
3. 1 <= S <= 1 000 000 000
4. 0 <= Wi, Pi, W, M <= 1 000
5. 0 <= W*M <= 1 000
6. 0 <= Vi <= 1 000 000

The first line contains a single integer T, indicating the number of test cases.
Each test case begins with four integers N, S, W, M. Then N lines following, each line contains three integers Pi, Wi, Vi, describing a present.

Technical Specification

1. 1 <= T <= 100
2. 1 <= N <= 1 000
3. 1 <= S <= 1 000 000 000
4. 0 <= Wi, Pi, W, M <= 1 000
5. 0 <= W*M <= 1 000
6. 0 <= Vi <= 1 000 000

2
2 2 3 4
1 1 2
1 2 3
2 3 3 4
1 1 2
1 2 3

Case 1: 2 2 3 5
Case 2: 3 3 3 6