Horse Cruise Control

Find the largest constant speed Annie can ride without passing any horse that slows as it catches leaders, expressed as a reduced fraction.

Medium6MathGreedySortingImplementationNo attempts yetTime limit5sMemory limit512 MB

Problem

Annie drives a bus and the job wears her down. She booked a Caribbean cruise to unwind, that turned out to be stressful too, so lately she rides horses instead.

Today Annie rides east along a long, narrow one way road that runs from west to east. She is at kilometer 0 of the road and her destination is at kilometer DD. Kilometer marks grow from west to east.

NN other horses travel east on the same road. All of them keep going forever, and all of them are currently between Annie's horse and her destination. Horse ii starts at kilometer KiK_i and runs at its maximum speed of SiS_i kilometers per hour.

Horses are very polite. A horse H1H_1 never passes a horse H2H_2 that started ahead of H1H_1. Two or more horses may share the same position for any amount of time, and each horse counts as a single point. Every horse other than Annie's runs at its maximum speed, except that once H1H_1 catches up to a slower horse H2H_2 ahead of it, H1H_1 drops to the speed of H2H_2.

Annie's horse has no maximum speed, so it runs at any speed Annie chooses as long as it passes no other horse. For a smooth ride Annie wants a single constant speed for the whole trip, from her current position to the destination, and that speed must never make her pass another horse. Find the largest such speed.

Input

The first line contains the number of test cases TT. TT test cases follow.

The first line of each test case contains two integers DD and NN. DD is the destination position of every horse in kilometers, and NN is the number of other horses on the road. Each of the next NN lines contains two integers KiK_i and SiS_i: the starting position in kilometers and the maximum speed in kilometers per hour of the ii-th of the other horses.

Limits

  • 1T1001 \le T \le 100
  • 0<Ki<D1090 < K_i < D \le 10^9 for all ii
  • KiKjK_i \ne K_j for all iji \ne j (no two horses start at the same position)
  • 1Si100001 \le S_i \le 10000
  • 1N10001 \le N \le 1000

Output

For each test case, print one line of the form Case #x: p/q, where x is the test case number starting from 1 and p/q is the largest constant speed in kilometers per hour that Annie can hold without passing another horse, written as a fraction in lowest terms.

The answer is always rational. Use integers pp and qq with gcd(p,q)=1\gcd(p, q) = 1 and q1q \ge 1. When the answer is an integer nn, print the denominator anyway, as n/1.

Hint

The first test case of the example has one other horse, and it is very slow. It reaches Annie's destination after 25 hours. Anything faster than 101 kilometers per hour makes Annie pass that horse before she reaches the destination, so the answer is 101/1.

The second test case has two other horses. The faster one catches the slower one at kilometer 240 after 2 hours. Both then run at the slower horse's speed for 1 more hour and reach the destination at kilometer 300. The largest speed Annie can choose without passing another horse is 100 kilometers per hour, so the answer is 100/1.