#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
const int maxn=1000005;
char str[maxn],sub[maxn];
int next[maxn];
void get_next(char *sub)//构造next 函数
{
int i=1,j=0;
next[1]=0;
while(sub[i])
{
if(sub[i]==sub[j]||j==0)
{
++i;++j;next[i]=j;
}
else j=next[j];
}
}
//判断sub是否是str的子串,匹配不成功返回-1,匹配成功返回第一次匹配的首位置
int kmp(char *str,char *sub)
{
int i=1,j=1,ans=0;
while(str[i])
{
if(str[i]==sub[j]||j==0)
{
i++;j++;
}
else j=next[j];
if(sub[j]==0)
{
//ans++;j=next[j];//求有多少个子串
return i-strlen(sub);
}
}
//return ans;
return -1;
}
int main()
{
int t,cc=0;
cin>>t;
while (t--)
{
scanf("%s%s",str,sub);
get_next(sub);
printf("Case %d: %d\n",++cc,kmp(str,sub));
}
return 0;
}