//NiceDuck
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;
#define FILE "000"
#define foru(i,a,b) for(int i=(int)(a); i<=(int)(b); ++i)
#define ford(i,a,b) for(int i=(int)(a); i>=(int)(b); --i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define fi first
#define se second
#define el "\n"
#define MASK(i) (1LL<<(i))
#define BIT(i,j) (((i)>>(j))&1)
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define LOG 20

const ll MAX=1e4+4;
int n,l;
string str;

const ll BASE=311, MOD1=1e9+7, MOD2=1561023067;
ll h1[MAX],h2[MAX],p1[MAX],p2[MAX];
void buildHash()
{
    p1[0]=p2[0]=1;
    foru(i,1,l)
    {
        p1[i]=(p1[i-1]*BASE)%MOD1;
        p2[i]=(p2[i-1]*BASE)%MOD2;
        h1[i]=(h1[i-1]*BASE + (int)(str[i]))%MOD1;
        h2[i]=(h2[i-1]*BASE + (int)(str[i]))%MOD2;
    }
}
pair<ll,ll> getHash(int L, int R)
{
    ll x=(h1[R]-h1[L-1]*p1[R-L+1]+MOD1*MOD1)%MOD1;
    ll y=(h2[R]-h2[L-1]*p2[R-L+1]+MOD2*MOD2)%MOD2;
    return make_pair(x,y);
}
map<pair<ll,ll>,ll> mp;

ll pw(ll x, ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y&1) res=(res*x)%MOD1;
        x=(x*x)%MOD1;
        y>>=1;
    }
    return res;
}

int main()
{
    fastio
    if(fopen(FILE ".inp","r"))
    {
        freopen(FILE ".inp","r",stdin); freopen(FILE ".out","w",stdout);
    }
    cin>>str; cin>>n;
    l=str.size();
    str=" "+str;
    buildHash();
    foru(i,1,l)
    {
        ford(j,i,1)
        {
            pair<ll,ll> tmp=getHash(j,i);
            mp[tmp]++;
        }
    }
    ll ans=0;
    for(pair<pair<ll,ll>,ll> pa:mp)
    {
        ll x=pa.se;
        ans=(ans+pw(x,n))%MOD1;
    }
    cout<<ans;

    return 0;
}
