VK gave a problem to Chef, but Chef is too lazy, so he asked you to solve the problem for him. The statement of the problem follows.
Consider an integer with $N$ digits (in decimal notation, without leading zeroes) $D_1, D_2, D_3, \dots, D_N$. Here, $D_1$ is the most significant digit and $D_N$ the least significant. The weight of this integer is defined as ∑i=2N(Di−Di−1).∑i=2N(Di−Di−1).\sum_{i=2}^N (D_i - D_{i-1})\,.
You are given integers $N$ and $W$. Find the number of positive integers with $N$ digits (without leading zeroes) and weight equal to $W$. Compute this number modulo $10^9+7$.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first and only line of each test case contains two space-separated integers $N$ and $W$ denoting the number of digits and the required weight.

-----Output-----
For each test case, print a single line containing one integer — the number of $N$-digit positive integers with weight $W$, modulo $10^9+7$.

-----Constraints-----
- $1 \le T \le 10^5$
- $2 \le N \le 10^{18}$
- $|W| \le 300$

-----Subtasks-----
Subtask #1 (20 points):
- $1 \le T \le 10^3$
- $2 \le N \le 10^3$
Subtask #2 (80 points): original constraints

-----Example Input-----

1
2 3

-----Example Output-----

6

-----Explanation-----
Example case 1: Remember that the digits are arranged from most significant to least significant as $D_1, D_2$. The two-digit integers with weight $3$ are $14, 25, 36, 47, 58, 69$. For example, the weight of $14$ is $D_2-D_1 = 4-1 = 3$. We can see that there are no other possible numbers.

Starter code:

Solutions:
for _ in range(int(input())):
 n,w = map(int , input().split())
 sigma = 1
 #len(str(num)) == n and D[i] - D[i - 1] ... = w
 if(w > 9 or w < -9):
  print(0)
  continue
 sigma = pow(10,n - 2,1000000007)
 if(w >= 0):
  sigma *= (9 - w)
 else:
  sigma *= (w + 10)
 print(sigma % 1000000007)

# cook your dish here

mod=10**9+7
store=dict()
def power10(N):
 x=bin(N)
 i=-1
 tmp=10
 r=1
 while x[i]!='b':
  if x[i]=='1':
   r*=tmp
   r%=mod
  #print(tmp,r,tmp*r)
  tmp=(tmp%mod)*(tmp%mod)
  tmp%=mod
  i-=1
 return r%mod

from sys import stdin, stdout
T=int(input().strip())

for _ in range(T):
 N,W=map(int,input().strip().split())
 dp=[-1]*(N+1)
 dp[0]=1
 if W>8 or W<-9:
  print(0)
 else:
  if W>=0:
   if store.get(N-2)==None:
    store[N-2]=power10(N-2)
   res=(9-W)*store[N-2]
  else:
   if store.get(N-2)==None:
    store[N-2]=power10(N-2)
   res=(W+10)*store[N-2]
  print(res%mod)

# cook your dish here

mod=10**9+7

def power10(N):
 x=bin(N)
 i=-1
 tmp=10
 r=1
 while x[i]!='b':
  if x[i]=='1':
   r*=tmp
   r%=mod
  #print(tmp,r,tmp*r)
  tmp=(tmp%mod)*(tmp%mod)
  tmp%=mod
  i-=1
 return r

from sys import stdin, stdout
T=int(input().strip())

for _ in range(T):
 N,W=map(int,input().strip().split())
 dp=[-1]*(N+1)
 dp[0]=1
 if W>8 or W<-9:
  print(0)
 else:
  if W>=0:
   res=(9-W)*power10(N-2)
  else:
   res=(W+10)*power10(N-2)
  print(res%mod)

# cook your dish here

mod=10**9+7

def power10(N):
 if N==0:
  return dp[0]
 if N%2==1:
  dp[N]=(10*power10(N-1))%mod
  return((10*power10(N-1))%mod)
 else:
  if dp[N//2]==-1:
   dp[N//2]=power10(N//2)%mod
  dp[N]=(dp[N//2]**2)%mod
  return(dp[N]%mod)

from sys import stdin, stdout
T=int(input().strip())

for _ in range(T):
 N,W=map(int,input().strip().split())
 dp=[-1]*(N+1)
 dp[0]=1
 if W>8 or W<-9:
  print(0)
 else:
  if W>=0:
   res=(9-W)*power10(N-2)
  else:
   res=(W+10)*power10(N-2)
  print(res%mod)

# cook your dish here
from sys import stdin, stdout
T=int(input().strip())
mod=10**9+7
for _ in range(T):
 N,W=map(int,input().strip().split())
 if W>8 or W<-9:
  print(0)
 else:
  if W>=0:
   res=(9-W)*((10**(N-2))%mod)
  else:
   res=(W+10)*((10**(N-2))%mod)
  print(res%mod)


m=int(pow(10,9)+7)
for i in range(int(input())):
 n,w=list(map(int,input().split()))
 s=0
 for i in range(1,10):
  for j in range(10):
   if(j-i==w):
    s+=1
 print((s*pow(10,n-2,m))%m)


# cook your dish here
mo = 10**9 + 7
def findNumbers(n, w): 
 x = 0; 
 s = 0; 
 if (w >= 0 and w <= 8): 
  x = 9 - w; 
 elif (w >= -9 and w <= -1): 
  x = 10 + w;     
 s = pow(10, n - 2,mo); 
 s *= (x%mo);    
 return s%mo; 

for i in range(int(input())):
 n,w = map(int,input().split())
 print(findNumbers(n,w))

def abc(i,n,w,x,c):
 if c==n:
  return x==w
 ans=0
 for j in range(10):
  ans+=abc(j,n,w,x+j-i,c+1)
 return ans
e=10**9+7
t=int(input())
for _ in range(t):
 n,w=list(map(int,input().split()))
 ans=0
 for i in range(1,10):
  pass
  #ans+=abc(i,n,w,0,1)
 #print(ans)
 if n==1:
  if w==0:
   print(9)
  else:
   print(0)
 else:
  if w>=9:
   print(0)
  elif w>0:
   x = ((9-w)*pow(10,n-2,e))%e
   print(x)
  elif w<=-10:
   print(0)
  elif w==0:
   print((9*pow(10,n-2,e))%e)
  else:
   c = -w
   x=((10-c)*pow(10,n-2,e))%e
   print(x)
 
  
0


m = 10**9 + 7
def findNumbers(n, w): 
 x,s = 0,0 
 if (w >= 0 and w <= 8): 
  x = 9 - w; 
 elif (w >= -9 and w <= -1): 
  x = 10 + w;     
 s = (pow(10, n - 2,m)*(x%m));   
 return s%m; 
for _ in range(int(input())):
 n,w = map(int,input().split())
 print(findNumbers(n,w))

from math import ceil
m=int(pow(10,9)+7)
t=int(input())
while(t):
 t-=1
 n,w=list(map(int,input().split()))
 ss=0
 for i in range(1,10):
  for j in range(10):
   if(j-i==w):
    ss+=1
 print((ss*pow(10,n-2,m))%m)


from math import ceil
m=int(pow(10,9)+7)
t=int(input())
while(t):
 t-=1
 n,w=list(map(int,input().split()))
 ss=0
 for i in range(1,10):
  for j in range(10):
   if(j-i==w):
    ss+=1
 print((ss*pow(10,n-2,m))%m)


t = int(input())
for i in range(t):
 lst = input().split()
 n = int(lst[0])
 w = int(lst[1])
 res = 0
 m = 10**9 + 7
 for j in range(1 , 10):
  for k in range(10):
   if(k - j == w):
    res += 1
 print(res * (10 ** (n - 2)) % m)

from math import ceil
m=int(pow(10,9)+7)
t=int(input())
while(t):
 t-=1
 n,w=list(map(int,input().split()))
 ss=0
 for i in range(1,10):
  for j in range(10):
   if(j-i==w):
    ss+=1
 print((ss*pow(10,n-2,m))%m)


m = 10**9 + 7
def findNumbers(n, w): 
 x = 0; 
 s = 0; 
 if (w >= 0 and w <= 8): 
  x = 9 - w; 
 elif (w >= -9 and w <= -1): 
  x = 10 + w;     
 s = pow(10, n - 2,m); 
 s *= (x%m);     
 return s%m; 
for _ in range(int(input())):
 n,w = map(int,input().split())
 print(findNumbers(n,w))

# Python3 program to find total possible 
# numbers with n digits and weight w 

# Function to find total possible 
# numbers with n digits and weight w 
m = 10**9 + 7
def findNumbers(n, w): 

 x = 0; 
 s = 0; 

 # When Weight of an integer 
 # is Positive 
 if (w >= 0 and w <= 8): 
  # Subtract the weight from 9 
  x = 9 - w; 
 
 # When weight of an integer 
 # is negative 
 elif (w >= -9 and w <= -1): 
  
  # add the weight to 10 to 
  # make it positive 
  x = 10 + w; 
 
 s = pow(10, n - 2,m); 
 s *= (x%m); 
 
 return s%m; 

# Driver code 

# number of digits in an 
# integer and w as weight 


# This code is contributed 
# by mits

for _ in range(int(input())):
 n,w = list(map(int,input().split()))
 print(findNumbers(n,w)%m)


# Python3 program to find total possible 
# numbers with n digits and weight w 

# Function to find total possible 
# numbers with n digits and weight w 
def findNumbers(n, w): 

 x = 0; 
 s = 0; 

 # When Weight of an integer 
 # is Positive 
 if (w >= 0 and w <= 8): 
  # Subtract the weight from 9 
  x = 9 - w; 
 
 # When weight of an integer 
 # is negative 
 elif (w >= -9 and w <= -1): 
  
  # add the weight to 10 to 
  # make it positive 
  x = 10 + w; 
 
 s = pow(10, n - 2); 
 s = (x * s); 
 
 return s; 

# Driver code 

# number of digits in an 
# integer and w as weight 


# This code is contributed 
# by mits
m = 10**9 + 7
for _ in range(int(input())):
 n,w = list(map(int,input().split()))
 print(findNumbers(n,w)%m)


m = (10**9) + 7 
t = int(input())
for i in range(t):
 N,W = map(int,input().split())
 if W>=0 and W <= 8:
  r = 9 - W
  print((pow(10,(N - 2),m) * (r%m))%m)
 elif W > 8:
  print(0)
 elif W < 0 and W >= - 9:
  s = 10 - abs(W)
  print((pow(10,(N - 2),m) * (s%m))%m)
 else:
  print(0)

# Hello World program in Pytho
# cook your dish here
for i in range(int(input())):
 n,w=map(int,input().split())
 c=0
 m=10**9+7
 if w>=-9 and w<=8:
  for i in range(1,10):
   for j in range(10):
    if j-i==w:
     c+=1
  if n==2:
   print(c)
  elif n>2:
   c=(pow(10,(n-2),m)*(c%m))%m
   print(c)
 else:
  print(0)

# Hello World program in Pytho
# cook your dish here
for i in range(int(input())):
 n,w=map(int,input().split())
 c=0
 m=10**9+7
 if w>=-9 and w<=8:
  for i in range(1,10):
   for j in range(10):
    if j-i==w:
     c+=1
  if n==2:
   print(c)
  elif n>2:
   c=((10**(n-2)%m)*(c%m))%m
   print(c)
 else:
  print(0)

# Hello World program in Pytho
# cook your dish here
for i in range(int(input())):
 n,w=map(int,input().split())
 c=0
 m=10**9+7
 if w>=-9 and w<=8:
  for i in range(1,10):
   for j in range(10):
    if j-i==w:
     c+=1
  if n==2:
   print(c)
  elif n>2:
   c*=10**(n-2)
   c=c%m
   print(c)
 else:
  print(0)

DIVISOR = 10**9 + 7
def main():
 T = int(input())
 for t in range(T):
  N, W = list(map(int, input().split(' ')))
  if W>8 or W<-9:
   print(0)
   continue
  
  if W>=0:
   first_digits = 9-W
  elif W<0:
   first_digits = 10+W

  print( (first_digits * pow(10, N-2, DIVISOR))%DIVISOR )

main()




DIVISOR = 10**9 + 7
def main():
 power_of_9s = [(10**n)%DIVISOR for n in range(1001)]
 T = int(input())
 for t in range(T):
  N, W = list(map(int, input().split(' ')))
  if W>8 or W<-9:
   print(0)
   continue
  
  if W>=0:
   first_digits = 9-W
  elif W<0:
   first_digits = 10+W

  mid_digits = power_of_9s[N-2]
  print( (first_digits * mid_digits)%DIVISOR )

main()