#pragma region include
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<queue>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<string.h>
#include<string>
#include<map>
#include<algorithm>
#include<time.h>
#include<set>
#include<vector>
#include<numeric>
#include<iomanip>
#include <bitset>
#include <functional>
using namespace std;
#pragma endregion
#pragma region define
#define All(a) a.begin(), a.end()
#define _2d(a,row,col,type) type**a=new type*[row]; for (int i=0;i<row;i++) a[i]=new type[col];
#define rep(i,n) for(int i=0;i<int(n);i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define repi(i,a,n) for(int i=int(a);i<int(n);i++)
#define clr(a, n) memset(a, n, sizeof(a));
#define scn(a,n) rep(i,n) cin>>a[i];
#define scn2(a,row,col) rep(i,row) rep(j,col) cin>>a[i][j];
#define prn(a,n) rep(i,n-1) cout<<a[i]<<" "; cout<<a[n-1]<<endl;
#define prn2(a,row,col) rep(i,row){rep(j,col-1) cout<<a[i][j]<<" "; cout<<a[i][col-1]<<endl;}
#define mp make_pair
#define Odd(x) x%2!=0
#define Even(x) x%2==0
#define Pi 3.14159265358979323846
#define INF 2000000000 // 2 billion
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define IOS ios::sync_with_stdio(false)
#define MOD (1e9 + 7)
#define SQR(x) (x) * (x)
#pragma endregion
#pragma region typedef
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef vector< int > vi;
typedef vector< vi > vivi;
typedef vector< long > vl;
typedef vector< ll> vll;
typedef vector< double > vd;
typedef vector< string> vs;
typedef pair< int , string> is;
typedef pair< int , int > pii;
typedef pair< pair< int ,int > , ll> pi;
#pragma endregion
int gcd( int a, int b) { return b == 0 ? a : gcd( b, a % b) ; }
int lcm( int a, int b) { return a * ( b / gcd( a, b) ) ; }
const int maxn = 10005 ;
char * s;
int n, gap;
int sa[ maxn] , pos[ maxn] , tmp[ maxn] , lcp[ maxn] ;
bool sufcmp( int i, int j)
{
if ( pos[ i] ! = pos[ j] )
return pos[ i] < pos[ j] ;
i + = gap;
j + = gap;
return ( i < n && j < n) ? pos[ i] < pos[ j] : i > j;
}
void buildsa( string s)
{
n = s.length ( ) ;
rep( i, n) sa[ i] = i, pos[ i] = s[ i] ;
for ( gap = 1 ;; gap * = 2 )
{
sort( sa, sa + n, sufcmp) ;
rep( i, n - 1 ) tmp[ i + 1 ] = tmp[ i] + sufcmp( sa[ i] , sa[ i + 1 ] ) ;
rep( i, n) pos[ sa[ i] ] = tmp[ i] ;
if ( tmp[ n - 1 ] == n - 1 ) break ;
}
}
void buildlcp( string s)
{
for ( int i = 0 , k = 0 ; i < n; ++ i) if ( pos[ i] ! = n - 1 )
{
for ( int j = sa[ pos[ i] + 1 ] ; s[ i + k] == s[ j + k] ; )
++ k;
lcp[ pos[ i] ] = k;
if ( k) -- k;
}
}
int main( )
{
//read;
//write;
int t, k = 1 ;
cin >> t;
string s;
while ( t-- ) {
cin >> s;
buildsa( s) ;
buildlcp( s) ;
ll res = 0 ;
int A, B; cin >> A >> B;
rep( i, n) {
if ( n - s[ i] < A) continue ;
int to_add;
int l = n - sa[ i] ;
int up, down;
up = min( l, B) ;
down = max( A, lcp[ i] ) ;
to_add = max( 0 , up - down) ;
res + = to_add;
}
cout << "Case " << k++ << ": " << res << endl;
clr( tmp, 0 ) ;
clr( lcp, 0 ) ;
clr( sa, 0 ) ;
clr( pos, 0 ) ;
}
return 0 ;
}
I3ByYWdtYSByZWdpb24gaW5jbHVkZQoKI2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwojaW5jbHVkZTxzdGRpby5oPgojaW5jbHVkZTxpb3N0cmVhbT4KI2luY2x1ZGU8c3N0cmVhbT4KI2luY2x1ZGU8cXVldWU+CiNpbmNsdWRlPG1hdGguaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPHN0YWNrPgojaW5jbHVkZTxzdHJpbmcuaD4KI2luY2x1ZG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