#include <bits/stdc++.h>
using namespace std;
const long long P = 10007;
const int M = 210, LIM = 700;
int n, m, i, j, k, f[LIM + 5][M][M];
char s[M];
long long powmod(long long a, long long b) {
  long long t = 1;
  a %= P;
  for (; b; b >>= 1, a = a * a % P)
    if (b & 1) t = t * a % P;
  return t;
}
namespace linear_seq {
const int N = 10010;
long long res[N], base[N], _c[N], _md[N];
vector<int> Md;
void mul(long long* a, long long* b, int k) {
  for (int i = 0; i < k + k; i++) _c[i] = 0;
  for (int i = 0; i < k; i++)
    if (a[i])
      for (int j = 0; j < k; j++) _c[i + j] = (_c[i + j] + a[i] * b[j]) % P;
  for (int i = k + k - 1; i >= k; i--)
    if (_c[i])
      for (int j = 0; j < ((int)(Md).size()); j++)
        _c[i - k + Md[j]] = (_c[i - k + Md[j]] - _c[i] * _md[Md[j]]) % P;
  for (int i = 0; i < k; i++) a[i] = _c[i];
}
int solve(long long n, vector<int> a, vector<int> b) {
  long long ans = 0, pnt = 0;
  int k = ((int)(a).size());
  for (int i = 0; i < k; i++) _md[k - 1 - i] = -a[i];
  _md[k] = 1;
  Md.clear();
  for (int i = 0; i < k; i++)
    if (_md[i]) Md.push_back(i);
  for (int i = 0; i < k; i++) res[i] = base[i] = 0;
  res[0] = 1;
  while ((1LL << pnt) <= n) pnt++;
  for (int p = pnt; p >= 0; p--) {
    mul(res, res, k);
    if ((n >> p) & 1) {
      for (int i = k - 1; i >= 0; i--) res[i + 1] = res[i];
      res[0] = 0;
      for (int j = 0; j < ((int)(Md).size()); j++)
        res[Md[j]] = (res[Md[j]] - res[k] * _md[Md[j]]) % P;
    }
  }
  for (int i = 0; i < k; i++) ans = (ans + res[i] * b[i]) % P;
  if (ans < 0) ans += P;
  return ans;
}
vector<int> BM(vector<int> s) {
  vector<int> C(1, 1), B(1, 1);
  int L = 0, m = 1, b = 1;
  for (int n = 0; n < ((int)(s).size()); n++) {
    long long d = 0;
    for (int i = 0; i < L + 1; i++) d = (d + (long long)C[i] * s[n - i]) % P;
    if (!d)
      ++m;
    else if (2 * L <= n) {
      vector<int> T = C;
      long long c = P - d * powmod(b, P - 2) % P;
      while (((int)(C).size()) < ((int)(B).size()) + m) C.push_back(0);
      for (int i = 0; i < ((int)(B).size()); i++)
        C[i + m] = (C[i + m] + c * B[i]) % P;
      L = n + 1 - L;
      B = T;
      b = d;
      m = 1;
    } else {
      long long c = P - d * powmod(b, P - 2) % P;
      while (((int)(C).size()) < ((int)(B).size()) + m) C.push_back(0);
      for (int i = 0; i < ((int)(B).size()); i++)
        C[i + m] = (C[i + m] + c * B[i]) % P;
      ++m;
    }
  }
  return C;
}
int gao(vector<int> a, long long n) {
  vector<int> c = BM(a);
  c.erase(c.begin());
  for (int i = 0; i < ((int)(c).size()); i++) c[i] = (P - c[i]) % P;
  return solve(n, c, vector<int>(a.begin(), a.begin() + ((int)(c).size())));
}
}  // namespace linear_seq
inline void up(int& a, int b) { a = (a + b) % P; }
int main() {
  scanf("%s%d", s + 1, &n);
  m = strlen(s + 1);
  f[0][1][m] = 1;
  for (i = 0; i < LIM; i++)
    for (j = 1; j <= m + 1; j++)
      for (k = max(j - 5, 0); k <= m; k++)
        if (f[i][j][k]) {
          if (j > k)
            up(f[i + 1][j][k], f[i][j][k] * 26);
          else if (s[j] == s[k]) {
            up(f[i + 1][j][k], f[i][j][k] * 25);
            up(f[i + 1][j + 1][k - 1], f[i][j][k]);
          } else {
            up(f[i + 1][j][k], f[i][j][k] * 24);
            up(f[i + 1][j + 1][k], f[i][j][k]);
            up(f[i + 1][j][k - 1], f[i][j][k]);
          }
        }
  vector<int> seq;
  for (i = m + 1; i <= LIM * 2; i++) {
    int now = 0;
    if (i & 1) {
      for (j = 1; j <= m + 1; j++)
        for (k = max(j - 5, 0); k <= m; k++)
          if (f[i / 2][j][k]) {
            if (j > k)
              up(now, f[i / 2][j][k] * 26);
            else if (j == k)
              up(now, f[i / 2][j][k]);
          }
    } else {
      for (j = 1; j <= m + 1; j++)
        for (k = max(j - 5, 0); k < j; k++)
          if (f[i / 2][j][k]) up(now, f[i / 2][j][k]);
    }
    seq.push_back(now);
  }
  printf("%d", linear_seq::gao(seq, n - 1));
}
