#include <bits/stdc++.h>
using namespace std;
const int p = 10007;
int n, m, f[510][210][210], a[310][310];
char s[210];
bool odd;
int power(int x, int k) {
  int ret = 1;
  for (; k; k >>= 1, x = x * x % p)
    if (k & 1) ret = ret * x % p;
  return ret;
}
void gauss_elimination(int n) {
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j)
      if (a[j][i]) {
        for (int k = i; k <= n; ++k) swap(a[i][k], a[j][k]);
        swap(a[i][0], a[j][0]);
        break;
      }
    int t = power(a[i][i], p - 2);
    for (int j = i; j <= n; ++j) (a[i][j] *= t) %= p;
    (a[i][0] *= t) %= p;
    for (int j = 1; j <= n; ++j)
      if (i != j && a[j][i]) {
        a[j][0] = (a[j][0] + p - a[j][i] * a[i][0] % p) % p;
        for (int k = n; k >= i; --k)
          a[j][k] = (a[j][k] + p - a[j][i] * a[i][k] % p) % p;
      }
  }
}
int main() {
  scanf("%s%d", s + 1, &m), m += n = strlen(s + 1);
  f[0][1][n] = 1;
  int x = n - 1, y = (n + 1) / 2;
  for (int i = 0; i <= x + y + n; ++i) {
    for (int j = 1; j <= n; ++j)
      for (int k = j; k <= n; ++k)
        if (f[i][j][k])
          if (s[j] == s[k]) {
            (f[i + 1][j][k] += f[i][j][k] * 25) %= p;
            (f[i + 1][j + 1][max(j, k - 1)] += f[i][j][k]) %= p;
          } else {
            (f[i + 1][j][k] += f[i][j][k] * 24) %= p;
            (f[i + 1][j + 1][k] += f[i][j][k]) %= p;
            (f[i + 1][j][k - 1] += f[i][j][k]) %= p;
          }
    for (int j = 0; j <= n; ++j)
      (f[i + 1][j + 1][j] += f[i][j + 1][j] * 26) %= p;
  }
  for (int i = 1; i <= x + y + 1; ++i) {
    for (int j = 0; j <= n; ++j)
      if (m & 1)
        (a[i][0] += f[i + n - 2 - 1][j + 1][j] * 26 + f[i + n - 2 - 1][j][j]) %=
            p;
      else
        (a[i][0] += f[i + n - 2][j + 1][j]) %= p;
    int t = power(24, i + n - 2);
    for (int j = 1; j <= x; ++j) a[i][j] = t, (t *= i + n - 2) %= p;
    t = power(25, i + n - 2);
    for (int j = 1; j <= y; ++j) a[i][j + x] = t, (t *= i + n - 2) %= p;
    a[i][x + y + 1] = power(26, i + n - 2);
  }
  gauss_elimination(x + y + 1), m = (m + 1) / 2;
  int ans = power(26, m) * a[x + y + 1][0] % p, t = power(24, m);
  for (int j = 1; j <= x; ++j) (ans += a[j][0] * t) %= p, (t *= m % p) %= p;
  t = power(25, m);
  for (int j = 1; j <= y; ++j) (ans += a[j + x][0] * t) %= p, (t *= m % p) %= p;
  printf("%d\n", ans);
  return 0;
}
