Problem: Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly n lowercase English letters into s to make it a palindrome. (A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.) You can choose any n lowercase English letters, and insert each of them to any position of s, possibly to the beginning or the end of s. You have to insert exactly n letters even if it is possible to turn s into a palindrome by inserting less than n letters.

Find the number of the palindromes that can be obtained in this way, modulo 10007.

Input

The first line contains a string s (1 ≤ |s| ≤ 200). Each character in s is a lowercase English letter.

The second line contains an integer n (1 ≤ n ≤ 109).

Output

Print the number of the palindromes that can be obtained, modulo 10007.

Examples

Input

revive
1


Output

1


Input

add
2


Output

28

Note

For the first sample, you can obtain the palindrome "reviver" by inserting 'r' to the end of "revive".

For the second sample, the following 28 palindromes can be obtained: "adada", "adbda", ..., "adzda", "dadad" and "ddadd".

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MXL = 5000;
const int mo = 10007;
const double pi = acos(-1);
const int PL = 4096;
int N, len;
int bitr[MXL];
struct comp {
  double x, y;
  comp(const double x_ = 0, const double y_ = 0) {
    x = x_;
    y = y_;
  }
};
comp operator+(comp a, comp b) { return comp(a.x + b.x, a.y + b.y); }
comp operator-(comp a, comp b) { return comp(a.x - b.x, a.y - b.y); }
comp operator*(comp a, comp b) {
  return comp(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
comp conj(comp a) { return comp(a.x, -a.y); }
comp A[MXL], B[MXL];
double cs[MXL], si[MXL];
void prepare() {
  for (int i = 0; i <= N - 1; i++) {
    bitr[i] = 0;
    for (int j = 0; j <= len - 1; j++)
      if ((i & (1 << j)) > 0) bitr[i] ^= (1 << (len - 1 - j));
  }
}
void DFT(comp *a) {
  for (int i = 0; i <= N - 1; i++)
    if (i < bitr[i]) swap(a[i], a[bitr[i]]);
  for (int now = 2; now <= N; now <<= 1) {
    int half = now / 2;
    for (int i = 0; i <= half - 1; i++) {
      comp w = comp(cs[PL / now * i], si[PL / now * i]);
      for (int j = i; j < N; j += now) {
        comp l = a[j], r = a[j + half] * w;
        a[j + half] = l - r;
        a[j] = l + r;
      }
    }
  }
}
void IDFT(comp *a) {
  for (int i = 0; i <= N - 1; i++)
    if (i < bitr[i]) swap(a[i], a[bitr[i]]);
  for (int now = 2; now <= N; now <<= 1) {
    int half = now / 2;
    for (int i = 0; i <= half - 1; i++) {
      comp w = comp(cs[PL / now * i], -si[PL / now * i]);
      for (int j = i; j < N; j += now) {
        comp l = a[j], r = a[j + half] * w;
        a[j + half] = l - r;
        a[j] = l + r;
      }
    }
  }
  for (int i = 0; i <= N - 1; i++) {
    a[i].x = a[i].x / N;
    a[i].y = a[i].y / N;
  }
}
void fft(long long *a, long long *b, long long *tmp) {
  if (N <= 32) {
    for (int i = 0; i <= N - 1; i++) tmp[i] = 0;
    for (int i = 0; i <= N - 1; i++)
      if (a[i])
        for (int j = 0; j <= N - i - 1; j++)
          if (b[j]) tmp[i + j] = (tmp[i + j] + a[i] * b[j]);
    for (int i = 0; i <= N - 1; i++) tmp[i] = tmp[i] % mo;
    return;
  }
  for (int i = 0; i <= N - 1; i++) A[i] = comp(a[i], b[i]);
  DFT(A);
  for (int i = 0; i <= N - 1; i++) {
    comp x = A[i], y = A[i == 0 ? 0 : N - i];
    comp va = (x + conj(y)) * comp(0.5, 0), vb = (x - conj(y)) * comp(0, -0.5);
    B[i] = va * vb;
  }
  IDFT(B);
  for (int i = 0; i <= N - 1; i++) {
    long long v = B[i].x + 0.3;
    tmp[i] = v % mo;
  }
}
void fft(int n, long long *a, int m, long long *b, long long *tmp) {
  N = 1, len = 0;
  while (N <= n + m) N <<= 1, len++;
  if (n * m <= N * len) {
    for (int i = 0; i <= n + m; i++) {
      tmp[i] = 0;
      for (int j = max(0, i - m); j <= n; j++)
        tmp[i] = (tmp[i] + a[j] * b[i - j]);
      tmp[i] = tmp[i] % mo;
    }
    return;
  }
  prepare();
  for (int i = n + 1; i <= N - 1; i++) a[i] = 0;
  for (int i = m + 1; i <= N - 1; i++) b[i] = 0;
  fft(a, b, tmp);
}
const int MAXN = 805;
char s[MAXN];
int n;
int f[405][405][405];
long long L;
int k;
long long add(long long x, long long y) {
  return x + y >= mo ? x + y - mo : x + y;
}
long long dec(long long x, long long y) { return x >= y ? x - y : x + mo - y; }
int trs[805][805];
long long s0[MAXN * 2], s1[MAXN * 2], s2[MAXN * 4];
long long js[MAXN * 2], inv[MAXN * 2], mi24[MAXN * 2], mi25[MAXN * 2];
long long quickmi(long long x, long long tim) {
  long long ans = 1;
  for (; tim; tim /= 2, x = x * x % mo)
    if (tim & 1) ans = ans * x % mo;
  return ans;
}
long long calc(int n, int m) { return js[n] * inv[m] % mo * inv[n - m] % mo; }
long long a[MAXN * 2], Mo[MAXN * 2];
long long mi[MAXN * 2], pdt[MAXN * 2];
int m;
long long res[MAXN * 2], dv[MAXN * 2];
long long ny[MAXN * 2], q0[MAXN * 2];
long long tmp[MAXN * 4];
void getNy(int n) {
  if (n == 1) {
    ny[0] = 1;
    return;
  }
  int l;
  getNy(l = n / 2 + (n & 1));
  N = 1, len = 0;
  while (N <= n + l + l) N <<= 1, len++;
  prepare();
  for (int i = l; i <= N - 1; i++) ny[i] = 0;
  for (int i = 0; i <= N - 1; i++) s0[i] = 0;
  for (int i = 0; i <= n - 1; i++) s0[i] = q0[i];
  fft(ny, ny, tmp);
  fft(tmp, s0, tmp);
  for (int i = 0; i <= n - 1; i++) ny[i] = (ny[i] * 2 + mo - tmp[i]) % mo;
}
void getny() {
  for (int i = 0; i <= m; i++) q0[i] = Mo[m - i];
  getNy(m);
}
void Mod() {
  int A = 0, B = m;
  for (int i = B * 2 - 2; i >= 0; i--)
    if (tmp[i]) {
      A = i;
      break;
    }
  if (A < B) {
    for (int i = 0; i <= B - 1; i++) res[i] = tmp[i];
    return;
  }
  for (int i = 0; i <= A - B; i++) s0[i] = tmp[A - i], s1[i] = ny[i];
  fft(A - B, s0, A - B, s1, dv);
  for (int i = A - B + 1; i <= N; i++) dv[i] = 0;
  reverse(dv, dv + A - B + 1);
  N = 1, len = 0;
  while (N <= A) N <<= 1, len++;
  prepare();
  for (int i = 0; i <= N - 1; i++) s0[i] = s1[i] = 0;
  for (int i = 0; i <= B; i++) s0[i] = Mo[i];
  for (int i = 0; i <= A - B; i++) s1[i] = dv[i];
  fft(s0, s1, dv);
  for (int i = 0; i <= B - 1; i++) res[i] = dec(tmp[i], dv[i]);
}
void multi(long long *a, long long *b, long long *c) {
  N = 1, len = 0;
  while (N <= m * 2) N <<= 1, len++;
  prepare();
  for (int i = m; i <= N - 1; i++) a[i] = b[i] = 0;
  fft(a, b, tmp);
  Mod();
  for (int i = 0; i <= m - 1; i++) c[i] = res[i];
}
int main() {
  for (int i = 0; i <= PL - 1; i++)
    cs[i] = cos(pi * 2 / PL * i), si[i] = sin(pi * 2 / PL * i);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  js[0] = js[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= n * 4; i++) js[i] = js[i - 1] * i % mo;
  for (int i = 2; i <= n * 4; i++)
    inv[i] = 1ll * (mo - mo / i) * inv[mo % i] % mo;
  for (int i = 2; i <= n * 4; i++) inv[i] = inv[i] * inv[i - 1] % mo;
  mi24[0] = mi25[0] = 1;
  for (int i = 1; i <= n * 4; i++)
    mi24[i] = mi24[i - 1] * 24 % mo, mi25[i] = mi25[i - 1] * 25 % mo;
  scanf("%I64d", &L);
  L = L + n;
  f[1][n][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = n; j >= i; j--)
      for (int k = 0; k <= min(i - 1, n - j); k++)
        if (f[i][j][k]) {
          if (s[i] == s[j])
            f[i + 1][j - 1][k + 1] = add(f[i + 1][j - 1][k + 1], f[i][j][k]);
          else {
            f[i + 1][j][k] = add(f[i + 1][j][k], f[i][j][k]);
            f[i][j - 1][k] = add(f[i][j - 1][k], f[i][j][k]);
          }
        }
  for (int i = 1; i <= n + 1; i++)
    for (int j = 0; j <= i - 1; j++)
      for (int k = 0; k <= min(i - 1, n - j); k++)
        if (f[i][j][k]) {
          int A = k, B = i - 1 + n - j - k * 2;
          trs[B][A] = add(trs[B][A], f[i][j][k]);
        }
  int ans = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      if (trs[i][j]) {
        m = i + j + 1;
        for (int x = 0; x <= m; x++) s0[x] = s1[x] = 0;
        if (!i)
          s0[0] = 1;
        else
          for (int x = 0; x <= i; x++)
            s0[x] = (x & 1) ? mo - mi24[x] * calc(i, x) % mo
                            : mi24[x] * calc(i, x) % mo;
        if (!j)
          s1[0] = 1;
        else
          for (int x = 0; x <= j; x++)
            s1[x] = (x & 1) ? mo - mi25[x] * calc(j, x) % mo
                            : mi25[x] * calc(j, x) % mo;
        for (int x = j + 1; x >= 1; x--)
          s1[x] = (s1[x] + mo - 1ll * s1[x - 1] * 26 % mo) % mo;
        fft(i, s0, j + 1, s1, s2);
        long long iv = quickmi(s2[m], mo - 2);
        for (int x = 0; x <= m; x++) Mo[x] = s2[m - x];
        for (int x = 0; x <= m; x++) s0[x] = s1[x] = 0;
        if (!i)
          s0[0] = 1;
        else
          for (int x = 0; x <= m; x++)
            s0[x] = mi24[x] * calc(x + i - 1, i - 1) % mo;
        if (!j)
          s1[0] = 1;
        else
          for (int x = 0; x <= m; x++)
            s1[x] = mi25[x] * calc(x + j - 1, j - 1) % mo;
        for (int x = 1; x <= m; x++)
          s1[x] = add(s1[x], 1ll * s1[x - 1] * 26 % mo);
        fft(m, s0, m, s1, s2);
        for (int x = 0; x <= m - 1; x++) ny[x] = a[x] = s2[x];
        long long tim = L / 2 - i - j;
        if (tim < 0) continue;
        for (int x = 0; x <= m; x++) pdt[x] = mi[x] = 0;
        mi[1] = 1;
        pdt[0] = 1;
        for (; tim; tim /= 2, multi(mi, mi, mi))
          if (tim & 1) multi(pdt, mi, pdt);
        long long sum = 0;
        for (int x = 0; x <= m - 1; x++) sum = (sum + 1ll * pdt[x] * a[x]) % mo;
        ans = (ans + sum * trs[i][j]) % mo;
      }
  if (L % 2 == 0)
    printf("%d\n", ans);
  else {
    long long sum = ans * 26 % mo;
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++) trs[i][j] = 0;
    for (int i = 1; i <= n; i++)
      for (int k = 0; k <= min(i - 1, n - i); k++)
        if (f[i][i][k]) {
          int A = k, B = i - 1 + n - i - k * 2;
          trs[B][A] = add(trs[B][A], f[i][i][k]);
        }
    int ans = 0;
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++)
        if (trs[i][j]) {
          if (i == 0 && j == 0) {
            long long sum = quickmi(25, L / 2);
            ans = (ans + sum * trs[i][j]) % mo;
            continue;
          }
          m = i + j + 1;
          for (int x = 0; x <= m; x++) s0[x] = s1[x] = 0;
          if (!i)
            s0[0] = 1;
          else
            for (int x = 0; x <= i; x++)
              s0[x] = (x & 1) ? mo - mi24[x] * calc(i, x) % mo
                              : mi24[x] * calc(i, x) % mo;
          if (!j)
            s1[0] = 1;
          else
            for (int x = 0; x <= j; x++)
              s1[x] = (x & 1) ? mo - mi25[x] * calc(j, x) % mo
                              : mi25[x] * calc(j, x) % mo;
          for (int x = j + 1; x >= 1; x--)
            s1[x] = (s1[x] + mo - 1ll * s1[x - 1] * 25 % mo) % mo;
          fft(i, s0, j + 1, s1, s2);
          long long iv = quickmi(s2[m], mo - 2);
          for (int x = 0; x <= m; x++) Mo[x] = s2[m - x];
          for (int x = 0; x <= m; x++) s0[x] = s1[x] = 0;
          if (!i)
            s0[0] = 1;
          else
            for (int x = 0; x <= m; x++)
              s0[x] = mi24[x] * calc(x + i - 1, i - 1) % mo;
          if (!j)
            s1[0] = 1;
          else
            for (int x = 0; x <= m; x++)
              s1[x] = mi25[x] * calc(x + j - 1, j - 1) % mo;
          for (int x = 1; x <= m; x++)
            s1[x] = add(s1[x], 1ll * s1[x - 1] * 25 % mo);
          fft(m, s0, m, s1, s2);
          for (int x = 0; x <= m - 1; x++) ny[x] = a[x] = s2[x];
          long long tim = L / 2 - i - j;
          if (tim < 0) continue;
          for (int x = 0; x <= m; x++) pdt[x] = mi[x] = 0;
          mi[1] = 1;
          pdt[0] = 1;
          for (; tim; tim /= 2, multi(mi, mi, mi)) {
            if (tim & 1) multi(pdt, mi, pdt);
          }
          long long sum = 0;
          for (int x = 0; x <= m - 1; x++)
            sum = (sum + 1ll * pdt[x] * a[x]) % mo;
          ans = (ans + sum * trs[i][j]) % mo;
        }
    sum = (sum + ans) % mo;
    cout << sum << endl;
  }
  return 0;
}