#include <bits/stdc++.h>
using namespace std;
const int N = 310, mo = 10007;
char c[N];
int n, m, ans, t;
int f[N][N][N], su[N];
struct mat {
  int a[N][N];
} a, b;
long long c2[N][N];
mat operator*(const mat& a, const mat& b) {
  mat c;
  memset(c2, 0, sizeof c2);
  for (int i = 1, _e = t; i <= _e; ++i)
    for (int j = 1, _e = t; j <= _e; ++j)
      for (int k = 1, _e = t; k <= _e; ++k) c2[i][k] += a.a[i][j] * b.a[j][k];
  for (int i = 1, _e = t; i <= _e; ++i)
    for (int j = 1, _e = t; j <= _e; ++j) c.a[i][j] = c2[i][j] % mo;
  return c;
}
mat ksm(mat x, int y) {
  mat b;
  memset(b.a, 0, sizeof b.a);
  for (int i = 1, _e = t; i <= _e; ++i) b.a[i][i] = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) b = b * x;
  return b;
}
int main() {
  scanf("%s\n%d", c + 1, &m);
  n = strlen(c + 1);
  f[1][n][0] = 1;
  for (int i = 1, _e = n; i <= _e; ++i)
    for (int j = n, _e = i; j >= _e; --j)
      if (c[i] == c[j]) {
        for (int k = 0, _e = n; k <= _e; ++k)
          if (i + 1 <= j - 1)
            (f[i + 1][j - 1][k] = (f[i + 1][j - 1][k] + f[i][j][k]) % mo);
          else
            (su[k] = (su[k] + f[i][j][k]) % mo);
      } else {
        for (int k = 0, _e = n - 1; k <= _e; ++k) {
          (f[i + 1][j][k + 1] = (f[i + 1][j][k + 1] + f[i][j][k]) % mo);
          (f[i][j - 1][k + 1] = (f[i][j - 1][k + 1] + f[i][j][k]) % mo);
        }
      }
  t = n + (n + 1 >> 1) + 1;
  a.a[t][t] = 26;
  for (int i = 1, _e = n; i <= _e; ++i) {
    a.a[i][i] = 24;
    a.a[i][n + (n - i + 1) / 2] = su[i];
    if (i < n) a.a[i][i + 1] = 1;
  }
  for (int i = n + 1, _e = t - 1; i <= _e; ++i) {
    a.a[i][i] = 25;
    if (i > n + 1)
      a.a[i][i - 1] = 1;
    else
      a.a[i][t] = 1;
  }
  b = ksm(a, n + m + 1 >> 1);
  ans = (b.a[1][t] + su[0] * b.a[t - 1][t]) % mo;
  if (n + m & 1) {
    for (int i = 0, _e = n; i <= _e; ++i) su[i] = 0;
    for (int i = 1, _e = n - 1; i <= _e; ++i)
      if (c[i] == c[i + 1])
        for (int j = 0, _e = n; j <= _e; ++j)
          (su[j] = (su[j] + f[i][i + 1][j]) % mo);
    for (int i = 1, _e = n; i <= _e; ++i) a.a[i][n + (n - i + 1) / 2] = su[i];
    a.a[t][t] = 0;
    b = ksm(a, n + m + 1 >> 1);
    ans = ((ans - b.a[1][t] - su[0] * b.a[t - 1][t]) % mo + mo) % mo;
  }
  cout << ans;
}
