SP7561 LEXIPOS - Lexicographic position
Description
Let us consider the set of integer numbers between 1 and N inclusive. Order them lexicographically (i. e. like in the vocabulary), for example, for N = 11 the order would be: 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9.
Denote the position of the number K in this ordering as Q $ _{N,K} $ . For example, Q $ _{11,2} $ = 4.
Given N and K, compute Q $ _{N,K} $ .
Input Format
The first line contains a number T, which is the number of test cases. T lines follow, each contains 2 integers N and K separated by a single space.
Output Format
For each test case, print Q $ _{N,K} $ on a single line.