/*
TASK:string
LANG:C++
*/
#include <iostream>

using namespace std;

string a,t;
int ch[125],s[2],p,end;

bool is_valid(int i)
{
	for(int j=0;j<p-1;j++)
	{
//		cout<<i<<" "<<j<<" "<<(1<<j)<<" "<<(i&(1<<j))<<" "<<(1<<j+1)<<" "<<(i&(1<<j+1))<<"\n";
		if((i&(1<<j))==s[1])
			if((i&(1<<j+1))==s[0])
			{
//				cout<<"...\n";
				return 0;
			}
	}
	return 1;
}

int res=0;
int main()
{
	cin>>a;
	cin>>t;
	ch[t[0]]=0;
	ch[t[1]]=1;
	s[0]=ch[a[0]];
	s[1]=ch[a[1]];
	cin>>p;
//	cout<<s[0]<<s[1]<<"\n";
	end=1<<p;
	for(int i=0;i<end;i++)
		if(is_valid(i))
			res++;
	cout<<res<<"\n";
    return 0;
}
