- All Contests
- ProjectEuler+
- Project Euler #112: Bouncy numbers

# Project Euler #112: Bouncy numbers

# Project Euler #112: Bouncy numbers

_{This problem is a programming version of Problem 112 from projecteuler.net}

Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, .

Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, .

We shall call a positive integer that is neither increasing nor decreasing a "bouncy" number; for example, .

Clearly there cannot be any bouncy numbers below one-hundred, but just over half of the numbers below one-thousand () are bouncy. In fact, the least number for which the proportion of bouncy numbers first reaches is .

Surprisingly, bouncy numbers become more and more common and by the time we reach the proportion of bouncy numbers is equal to .

Find the least number for which the proportion of bouncy numbers is at least .

**Input Format**

First line contains an integer denoting the number of test cases.

Each of the following lines contain two integers and .

**Constraints**

**Output Format**

For each of test cases print one line containing a single integer - the answer to a problem.

**Sample Input**

```
2
1 2
90 100
```

**Sample Output**

```
538
21780
```