#include<iostream>
#include<sstream>
#include<fstream>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<string.h>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<functional>
#include<algorithm>
//#include<memory.h>
#include<assert.h>
#include<numeric>
#include<limits.h>
using namespace std;
const int mod=1e9+7;
const int p=29;
long long pw[2005];
int n;
long long k;
string a,b;
long long hsh1[2005],hsh2[2005];
struct mat{long long a[2][2];}mt1;
int pw1(int i,int k)
{
	if(k==0)return 1;
	if(k==1)return i;
	long long res=pw1(i,k/2);
	res=res*res%mod;
	if(k&1)res=res*i%mod;
	return (int)res;
}
mat pw2(mat m,int k)
{
	if(k==0)return mt1;
	if(k==1)return m;
	mat res=pw2(m,k/2);
	mat mt3;
	for(int i=0;i<2;i++)for(int j=0;j<2;j++)mt3.a[i][j]=0;
	for(int i=0;i<2;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++)mt3.a[i][j]=(mt3.a[i][j]+(long long)(res.a[i][k]*res.a[k][j])%mod)%mod;
	res=mt3;
	if(k&1)
	{
		for(int i=0;i<2;i++)for(int j=0;j<2;j++)mt3.a[i][j]=0;
		for(int i=0;i<2;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++)mt3.a[i][j]=(mt3.a[i][j]+(long long)(res.a[i][k]*m.a[k][j])%mod)%mod;
		res=mt3;
	}
	return res;
}
int main()
{
	cin>>a>>b>>k;
	n=a.size();
	pw[0]=1;
	for(int i=1;i<2005;i++)pw[i]=pw[i-1]*p;
	int x=0,y=0;
	hsh1[n-1]=a[n-1];
	hsh2[n-1]=b[n-1];
	for(int i=n-2;i>=0;i--)hsh1[i]=hsh1[i+1]*p+a[i];
	for(int i=n-2;i>=0;i--)hsh2[i]=hsh2[i+1]*p+b[i];
	mt1.a[0][0]=1;
	mt1.a[0][1]=0;
	mt1.a[1][0]=0;
	mt1.a[1][1]=1;
	for(int i=0;i<n;i++)if(hsh1[i]+(hsh1[0]-hsh1[i]*pw[i])*pw[n-i]==hsh2[0])x++;else y++;
	if(x==0)
	{
		printf("0\n");
		return 0;
	}
	if(x==n)
	{
		printf("%d\n",pw1(x-1,k));
		return 0;
	}
	mat mt2;
	mt2.a[0][0]=x-1;
	mt2.a[0][1]=x;
	mt2.a[1][0]=y;
	mt2.a[1][1]=y-1;
	mt2=pw2(mt2,k);
	if(hsh1[0]==hsh2[0])printf("%d\n",mt2.a[0][0]);else printf("%d\n",mt2.a[0][1]);
	return 0;
}