#P16641. [GKS 2018 #B] No Nine

[GKS 2018 #B] No Nine

Problem Description

No Nine is a counting game that you can try when you are bored. In this game, you are only allowed to say numbers that are legal. A number is legal if and only if all of the following are true:

  • it is a natural number (i.e. in the set {1,2,3...}\{1, 2, 3...\})
  • it does not contain the digit 99 anywhere in its base 1010 representation
  • it is not divisible by 99

For example, the numbers 1616 and 1717 are legal. The numbers 1818, 1919, 17.217.2, and 17-17 are not legal.

On the first turn of the game, you choose and say a legal number FF. On each subsequent turn, you say the next legal number. For example, if you played a game with F=16F = 16, you would say 16,17,20,2116, 17, 20, 21, and so on.

Alice is very good at this game and never makes mistakes. She remembers that she played a game in which the first number was FF and the last number was LL (when she got tired of the game and stopped), and she wonders how many turns were in the game in total (that is, how many numbers she said).

Input Format

The input starts with one line containing one integer TT; TT test cases follow. Each test case consists of a single line containing two integers FF and LL: the first and last numbers from the game, as described above.

Output Format

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 11), and yy is the number of the turns played in the game.

2
16 26
88 102
Case #1: 9
Case #2: 4

Hint

In Sample Case #1, the game lasted for 9 turns, and the numbers Alice said were: 16,17,20,21,22,23,24,25,2616, 17, 20, 21, 22, 23, 24, 25, 26.

In Sample Case #2, the game lasted for 4 turns, and the numbers Alice said were: 88,100,101,10288, 100, 101, 102.

Limits

1T1001 \le T \le 100.

FF does not contain a 99 digit.

FF is not divisible by 99.

LL does not contain a 99 digit.

LL is not divisible by 99.

Small dataset (Test set 1 - Visible)

1F<L1061 \le F < L \le 10^6.

Large dataset (Test set 2 - Hidden)

1F<L10181 \le F < L \le 10^{18}.