Under construction

Still being built. Things may change

Increase and Decrease

Interview

Time limit1sMemory limit1024 MB

Summary
Count the increase-then-decrease numbers in each inclusive range [a, b] for up to 100000 queries, with a and b at most 10^6.
Level

Easy3 of 10

Topics
Prefix sum, Implementation
Solved
No attempts yet

x

Jeonghyeon, a student at Daegu Science High School, enjoys finding patterns in numbers. Lately he has become fascinated with increase-then-decrease numbers.

A positive integer is an increase-then-decrease number if its digits increase and then decrease when written in decimal without a leading zero. Formally, for a positive integer n=∑i=0k−1ai10i=ak−1ak−2⋯a1a0‾n=\sum_{i=0}^{k-1}a_i10^i=\overline{a_{k-1}a_{k-2}\cdots a_1a_0} with 0≤ai≤90\leq a_i\leq 9, aia_i an integer, and ak−1≠0a_{k-1}\neq 0, nn is an increase-then-decrease number if there exists some 1≤j≤k−21\leq j\leq k-2 such that ak−1<ak−2<⋯<aj+1<aj>aj−1>⋯>a1>a0a_{k-1}<a_{k-2}<\cdots<a_{j+1}<a_j>a_{j-1}>\cdots>a_1>a_0. For example, 1358613586 is an increase-then-decrease number because 1<3<5<8>61<3<5<8>6.

Given two positive integers aa and bb, count the increase-then-decrease numbers between aa and bb, inclusive.

Input

The first line contains the number of test cases tt.

Each of the next tt lines contains two positive integers aa and bb, separated by a space.

Output

For each test case, print the number of increase-then-decrease numbers between aa and bb, inclusive, on its own line.

Constraints

  • 1≤t≤1051 \leq t \leq 10^5
  • 1≤a≤b≤1061 \leq a \leq b \leq 10^6

Examples1

  1. Example 1

    Input
    2
    1 121
    3 20
    
    Expected output
    2
    0