#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const unsigned long long B1 = 139, B2 = 137;
const int SIZE = 1<<14;

struct  rolling_hash {
	unsigned long long h1,h2;

	void initialize() {
		h1=0ll;
		h2=0ll;
	}

	void append(char a) {
		h1*=B1;h1+=a-'a'+1;
		h2*=B2;h2+=a-'a'+1;
	}

	bool operator <(const rolling_hash &a) const {
		if(h1<a.h1) return true;
		if(h1>a.h1) return false;
		return h2<a.h2;
	}

	bool operator ==(const rolling_hash &a) const {
		return (h1==a.h1 && h2==a.h2);
	}
};

unsigned long long pow1[SIZE],pow2[SIZE];
char a[SIZE];
int n;
rolling_hash ph[SIZE];
int sa[SIZE];
int ans;
int lcp[SIZE];
int p,q;

void initialize_data() {
	ans=0;
}

rolling_hash get_hash(int from, int to) {
	rolling_hash h1,h2,ans;
	h1=ph[to];
	h2=ph[from-1];
	h2.h1=h2.h1*pow1[to-from+1];
	h2.h2=h2.h2*pow2[to-from+1];
	ans.h1=(h1.h1-h2.h1);
	ans.h2=(h1.h2-h2.h2);
	return ans;
}

bool sa_cmp(int x, int y) {
	int l1=n-x+1,l2=n-y+1;
	int left,right,middle;
	left=0;
	right=min(l1,l2);
	if(get_hash(x,x+right-1)==get_hash(y,y+right-1)) return x>y;
	while(right-left>1) {
		middle=(left+right)>>1;
		if(get_hash(x,x+middle-1)==get_hash(y,y+middle-1)) left=middle;
		else right=middle;
	}
	return a[x+left]<a[y+left];
}

void build_array() {
	int i;
	for(i=1;i<=n;i++) sa[i]=i;
	stable_sort(sa+1,sa+1+n,sa_cmp);
}

void build_lcp() {
	int i,left,right,middle,l1,l2;
	
	lcp[1]=0;
	for(i=2;i<=n;i++) {
		l1=n-sa[i]+1;
		l2=n-sa[i-1]+1;
		left=0;
		right=min(l1,l2);
		if(get_hash(sa[i],sa[i]+right-1)==get_hash(sa[i-1],sa[i-1]+right-1)) {
			lcp[i]=right;
		}
		else {
			while(right-left>1) {
				middle=(left+right)>>1;
				if(get_hash(sa[i],sa[i]+middle-1)==get_hash(sa[i-1],sa[i-1]+middle-1)) left=middle;
				else right=middle;
			}
			lcp[i]=left;
		}
	}
}

int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
//freopen("test.txt","r",stdin);
int tests,current_case;
rolling_hash h;
int i;

pow1[0]=1;
pow2[0]=1;
for(i=1;i<SIZE;i++)
	pow1[i]=pow1[i-1]*B1,
	pow2[i]=pow2[i-1]*B2;

scanf("%d", &tests);
for(current_case=1;current_case<=tests;current_case++) {
	scanf("%s", a+1);
	n=strlen(a+1);
	scanf("%d %d", &p, &q);
	
	initialize_data();
	
	h.initialize();
	ph[0]=h;
	for(i=1;i<=n;i++) {
		h.append(a[i]);
		ph[i]=h;
	}

	build_array();
	build_lcp();

	for(i=1;i<=n;i++) {
		if(n-sa[i]+1<p) continue;
		int to_add;
		int l=n-sa[i]+1;
		int up,down;
		up=min(l,q);
		down=max(p,lcp[i]+1);
		to_add=max(0,up-down+1);
		ans+=to_add;
	}

	printf("Case %d: %d\n", current_case, ans);

	a[n+1]='a';
}
return 0;
}
