atcoder#ABC295F. [ABC295F] substr = S

[ABC295F] substr = S

Score : 500500 points

Problem Statement

You are given a string SS consisting of digits and positive integers LL and RR for each of TT test cases. Solve the following problem.

For a positive integer xx, let us define f(x)f(x) as the number of contiguous substrings of the decimal representation of xx (without leading zeros) that equal SS.

For instance, if S=S= 22, we have f(122)=1f(122) = 1, f(123)=0f(123) = 0, f(226)=1f(226) = 1, and f(222)=2f(222) = 2.

Find k=LRf(k)\displaystyle \sum_{k=L}^{R} f(k).

Constraints

  • 1T10001 \le T \le 1000
  • SS is a string consisting of digits whose length is between 11 and 1616, inclusive.
  • LL and RR are integers satisfying 1LR<10161 \le L \le R < 10^{16}.

Input

The input is given from Standard Input in the following format, where casei\rm{case}_i denotes the ii-th test case:

TT

case1\rm{case}_{1}

case2\rm{case}_{2}

\vdots

caseT\rm{case}_{\it{T}}

Each test case is in the following format:

SS LL RR

Output

Print TT lines in total. The ii-th line should contain an integer representing the answer to the ii-th test case.

6
22 23 234
0295 295 295
0 1 9999999999999999
2718 998244353 9982443530000000
869120 1234567890123456 2345678901234567
2023032520230325 1 9999999999999999
12
0
14888888888888889
12982260572545
10987664021
1

This input contains six test cases.

  • In the first test case, S=S= 22, L=23L=23, R=234R=234.- f(122)=f(220)=f(221)=f(223)=f(224)==f(229)=1f(122)=f(220)=f(221)=f(223)=f(224)=\dots=f(229)=1.
    • f(222)=2f(222)=2.
    • Thus, the answer is 1212.
  • f(122)=f(220)=f(221)=f(223)=f(224)==f(229)=1f(122)=f(220)=f(221)=f(223)=f(224)=\dots=f(229)=1.
  • f(222)=2f(222)=2.
  • Thus, the answer is 1212.
  • In the second test case, S=S= 0295, L=295L=295, R=295R=295.- Note that f(295)=0f(295)=0.
  • Note that f(295)=0f(295)=0.