#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
typedef pair<LL,LL> pii;
typedef vector<LL> vi;
const LL Mod = (4294967296ULL);
const LL NN = 60;
char msg[NN],pat[NN];
LL LPS[NN],aut[NN][NN];
LL ans[NN][NN],def[NN][NN],temp[NN][NN];
int N;
void build_kmp(LL n,LL m){
assert(n < NN and m < NN);
LL k = LPS[0] = 0;
for(LL i = 1; i < n; ++i){
while(k > 0 and pat[i] != pat[k])
k = pat[k-1];
LPS[i] = (k += (pat[i] == pat[k]));
}
for(LL k = 0; k < n; ++k) for(LL i = 0; i < m; ++i){
if (k > 0 and pat[k] != msg[i])
aut[k][i] = aut[LPS[k-1]][i];
else
aut[k][i] = k + (pat[k] == msg[i]);
}
}
void mul(LL A[NN][NN],LL B[NN][NN],LL Ans[NN][NN]){
for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j){
Ans[i][j] = 0ULL;
for(int k = 0; k < N; ++k)
Ans[i][j] = ((A[i][k]*B[k][j])%Mod + Ans[i][j])%Mod;
}
}
void identity(LL A[NN][NN]){
memset(A,0,sizeof(A));
for(int i = 0; i < N; ++i)
A[i][i] = 1ULL;
}
void f(LL n){
if (n == 0){
identity(ans);
return;
}
f(n/2);
mul(ans,ans,temp);
memcpy(ans,temp,sizeof(temp));
if (n & 1) {
mul(ans,def,temp);
memcpy(ans,temp,sizeof(temp));
}
}
LL solve(){
memset(ans,0,sizeof(ans));
memset(def,0,sizeof(def));
memset(aut,0,sizeof(aut));
LL a,b;
LL n; cin >> n;
scanf("%s%s",msg,pat);
//dbg(msg); dbg(pat);
b = (LL)strlen(msg);
N = a = (LL)strlen(pat);
build_kmp(a,b);
for(LL i = 0; i < a; ++i) for(LL j = 0; j < b; ++j){
LL nxt = aut[i][j];
def[i][nxt] += (nxt < a);
}
f(n);
LL cnt = 0ULL;
for(LL k = 0; k < a; ++k)
cnt = (cnt + ans[0][k])%Mod;
return cnt;
}
int main()
{
LL t; cin >> t;
for(LL i = 1; i <= t; ++i){
cout << "Case " << i << ": " << solve() << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIHVuc2lnbmVkIGxvbmcgbG9uZyBMTDsKdHlwZWRlZiBwYWlyPExMLExMPiBwaWk7CnR5cGVkZWYgdmVjdG9yPExMPiB2aTsKCmNvbnN0IExMIE1vZCA9ICg0Mjk0OTY3Mjk2VUxMKTsKY29uc3QgTEwgTk4gPSA2MDsKCmNoYXIgbXNnW05OXSxwYXRbTk5dOwoKTEwgTFBTW05OXSxhdXRbTk5dW05OXTsKTEwgYW5zW05OXVtOTl0sZGVmW05OXVtOTl0sdGVtcFtOTl1bTk5dOwppbnQgTjsKCnZvaWQgYnVpbGRfa21wKExMIG4sTEwgbSl7CiAgICBhc3NlcnQobiA8IE5OIGFuZCBtIDwgTk4pOwogICAgTEwgayA9IExQU1swXSA9IDA7CiAgICBmb3IoTEwgaSA9IDE7IGkgPCBuOyArK2kpewogICAgICAgIHdoaWxlKGsgPiAwIGFuZCBwYXRbaV0gIT0gcGF0W2tdKQogICAgICAgICAgICBrID0gcGF0W2stMV07CiAgICAgICAgTFBTW2ldID0gKGsgKz0gKHBhdFtpXSA9PSBwYXRba10pKTsKICAgIH0KCiAgICBmb3IoTEwgayA9IDA7IGsgPCBuOyArK2spIGZvcihMTCBpID0gMDsgaSA8IG07ICsraSl7CiAgICAgICAgaWYgKGsgPiAwIGFuZCBwYXRba10gIT0gbXNnW2ldKQogICAgICAgICAgICBhdXRba11baV0gPSBhdXRbTFBTW2stMV1dW2ldOwogICAgICAgIGVsc2UKICAgICAgICAgICAgYXV0W2tdW2ldID0gayArIChwYXRba10gPT0gbXNnW2ldKTsKICAgIH0KfQoKdm9pZCBtdWwoTEwgQVtOTl1bTk5dLExMIEJbTk5dW05OXSxMTCBBbnNbTk5dW05OXSl7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgTjsgKytpKSBmb3IoaW50IGogPSAwOyBqIDwgTjsgKytqKXsKICAgICAgICBBbnNbaV1bal0gPSAwVUxMOwogICAgICAgIGZvcihpbnQgayA9IDA7IGsgPCBOOyArK2spCiAgICAgICAgICAgIEFuc1tpXVtqXSA9ICgoQVtpXVtrXSpCW2tdW2pdKSVNb2QgKyBBbnNbaV1bal0pJU1vZDsKICAgIH0KfQoKdm9pZCBpZGVudGl0eShMTCBBW05OXVtOTl0pewogICAgbWVtc2V0KEEsMCxzaXplb2YoQSkpOwogICAgZm9yKGludCBpID0gMDsgaSA8IE47ICsraSkKICAgICAgICBBW2ldW2ldID0gMVVMTDsKfQoKdm9pZCBmKExMIG4pewogICAgaWYgKG4gPT0gMCl7CiAgICAgICAgaWRlbnRpdHkoYW5zKTsKICAgICAgICByZXR1cm47CiAgICB9CgogICAgZihuLzIpOwogICAgbXVsKGFucyxhbnMsdGVtcCk7CiAgICBtZW1jcHkoYW5zLHRlbXAsc2l6ZW9mKHRlbXApKTsKICAgIGlmIChuICYgMSkgewogICAgICAgIG11bChhbnMsZGVmLHRlbXApOwogICAgICAgIG1lbWNweShhbnMsdGVtcCxzaXplb2YodGVtcCkpOwogICAgfQp9CgpMTCBzb2x2ZSgpewogICAgbWVtc2V0KGFucywwLHNpemVvZihhbnMpKTsKICAgIG1lbXNldChkZWYsMCxzaXplb2YoZGVmKSk7CiAgICBtZW1zZXQoYXV0LDAsc2l6ZW9mKGF1dCkpOwoKICAgIExMIGEsYjsKICAgIExMIG47IGNpbiA+PiBuOwogICAgc2NhbmYoIiVzJXMiLG1zZyxwYXQpOwoKICAgIC8vZGJnKG1zZyk7IGRiZyhwYXQpOwogICAgYiA9IChMTClzdHJsZW4obXNnKTsKICAgIE4gPSBhID0gKExMKXN0cmxlbihwYXQpOwogICAgYnVpbGRfa21wKGEsYik7CgogICAgZm9yKExMIGkgPSAwOyBpIDwgYTsgKytpKSBmb3IoTEwgaiA9IDA7IGogPCBiOyArK2opewogICAgICAgIExMIG54dCA9IGF1dFtpXVtqXTsKICAgICAgICBkZWZbaV1bbnh0XSArPSAobnh0IDwgYSk7CiAgICB9CgogICAgZihuKTsKICAgIExMIGNudCA9IDBVTEw7CiAgICBmb3IoTEwgayA9IDA7IGsgPCBhOyArK2spCiAgICAgICAgY250ID0gKGNudCArIGFuc1swXVtrXSklTW9kOwogICAgcmV0dXJuIGNudDsKfQoKaW50IG1haW4oKQp7CiAgICBMTCB0OyBjaW4gPj4gdDsKICAgIGZvcihMTCBpID0gMTsgaSA8PSB0OyArK2kpewogICAgICAgIGNvdXQgPDwgIkNhc2UgIiA8PCBpIDw8ICI6ICIgPDwgc29sdmUoKSA8PCBlbmRsOwogICAgfQogICAgcmV0dXJuIDA7Cn0K