/*
TASK: string
LANG: C++
*/

#include <iostream>
#include <string>
using namespace std;

string S, T;
int P;
int ans;

void input ()
{
     cin >> S;
     cin >> T;
     cin >> P;
}

void solve ()
{
     int i, j, br;
     int Scode=0;
     
     for (i=0; i<S.size(); i++) Scode |= (S[i]==S[0])<<i;
     
     for (i=0; i<(1<<P); i++) {
         br=0;
         for (j=0; j<P; j++) {
             if (((i>>j)&1) == ((Scode>>j)&1)) {
                          br++;
                          if (br==S.size()) {
                                     //cout << i << " " << Scode << endl;
                                     ans++;
                                     break;
                          }
             }
             else br=0;
         }
         cout << "." << endl;
     }
     
     ans = (1<<P) - ans;
}

int main ()
{
    input ();
    
    if (T.size() == 1) ans=0;
    else solve ();
    
    cout << ans << "\n";
    
    return 0;
}
