Contests | Virtual Contests | Problems | Submit | Runs Status | Rank List | Forum |

Time Limit: 1.0 Seconds Memory Limit: 65536K

Total Runs: 386 Accepted Runs: 148

John is moving to the penthouse of a tall sky-scraper. He
packed all his stuff in boxes and drove them to the entrance
of the building on the ground floor. Unfortunately
the elevator is out of order, so the boxes have to be moved
up the stairs.
### Input

### Output

### Sample Input

### Sample Output

Luckily John has a lot of friends that want to help carrying his boxes up. They all walk the stairway at the same speed of 1 floor per minute, regardless of whether they carry a box or not. The stairway however is so narrowthat two persons can't pass each other on it. Therefore they deciced to do the following: someonewith a box in his hands is always moving up and someone empty-handed is always moving down. When two persons meet each other somewhere on the stairway, the lower one (with a box) hands it over to the higher one (without a box). (And then the lower onewalks down again and the higher one walks up.) The box exchange is instantaneous. When someone is back on the ground floor, he picks up a box and starts walking up. When someone is at the penthouse, he drops the box and walks down again.

After a while the persons are scattered across the stairway, some of them with boxes in their hands and some without. There are still a number of boxes on the ground floor and John is wondering how much more time it will take before all the boxes are up. Help him to find out!

One line with a positive number: the number of test cases. Then for each test case:

- One line with three numbers N, F, B with 1 ≤ N, F ≤ 1,000 and 1 ≤ B ≤ 1,000,000: the number of persons, the number of floors (0=ground floor, F=penthouse) and the number of boxes that are still on the ground floor.
- N lines with two numbers
*f*and_{i}*b*with 0 ≤_{i}*f*≤ F and_{i}*b*= 0 or_{i}*b*= 1: the floors where the persons are initially and whether or not they have a box in their hands (1=box, 0=no box)._{i}

One line with the amount of time (in minutes) it will take to get all the remaining boxes to the penthouse.

2 3 10 5 0 0 0 0 0 0 2 5 1 2 1 3 0

30 8

Maintance:Fxz. Developer: SuperHacker, G.D.Retop, Fxz