Under construction

Still being built. Things may change

How Many Files

Interview

Time limit5sMemory limit512 MB

Summary
From printed percentage and count pairs, recover the unique total file count that fits every truncated percentage, or report that several fit.
Level

Medium5 of 10

Topics
Math
Solved
No attempts yet

Problem

A file transfer tool prints a status line while it runs. The line shows the percentage of files transferred so far and the number of files transferred so far:

 20% |==>-------|     1 files transferred
100% |==========|     5 files transferred

The percentage is not exact. The tool cuts it off at the decimal point, so both 1.2% and 1.7% print as 1%. Write PP for the printed percentage, KK for the printed count and FF for the total number of files. Every status line then satisfies P=⌊100K/F⌋P = \lfloor 100K/F \rfloor.

Users asked to see the total as well, so the line should become this:

 20% |==>-------|     1 out of 5 files transferred
100% |==========|     5 out of 5 files transferred

The total cannot always be recovered. Given the status lines printed during one transfer, report the total number of files, or report that more than one total fits.

The tool prints status lines at arbitrary moments. It does not print at fixed intervals, and it does not print once per transferred file. A total FF fits the status lines when F≥1F \ge 1, every printed count satisfies K≤FK \le F (the tool never transfers a file that does not exist), and every printed percentage satisfies P=⌊100K/F⌋P = \lfloor 100K/F \rfloor.

Input

The first line contains TT, the number of test cases. Each test case starts with a line containing NN, the number of status lines, followed by NN lines. The ii-th of them contains two integers PiP_i and KiK_i, the percentage and the count printed on that status line. The lines come in chronological order, so within a test case both PiP_i and KiK_i are nondecreasing.

Limits

  • 1≤T≤501 \le T \le 50
  • 1≤N≤1001 \le N \le 100
  • 0≤Pi≤1000 \le P_i \le 100
  • 0≤Ki≤10150 \le K_i \le 10^{15}
  • Every test case has at least one total that fits its status lines.
  • When exactly one total fits, that total is at most 101510^{15}.

Output

For each test case, print one line Case #x: y, where xx is the test case number starting from 1 and yy is the total number of files. When more than one total fits the status lines, print -1 in place of yy.

Examples1

  1. Example 1

    Input
    3
    2
    20 1
    100 5
    10
    25 241
    27 262
    43 407
    44 413
    57 536
    64 601
    67 637
    84 789
    95 893
    96 903
    10
    0 0
    8 2
    8 2
    17 4
    30 7
    39 9
    69 16
    73 17
    82 19
    91 21
    
    Expected output
    Case #1: 5
    Case #2: -1
    Case #3: 23