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".
#include <bits/stdc++.h>
using namespace std;
const int P = 200;
const int R = 3;
const int MAX = 1000010;
long long inv[MAX];
long long invfact[MAX];
void getinv(long long n) {
  inv[1] = 1;
  for (int i = 2; i < (n + 1); i++) {
    inv[i] = inv[10007LL % i] * (10007LL - 10007LL / i) % 10007LL;
  }
}
long long extgcd(long long a, long long b, long long& x, long long& y) {
  long long d = a;
  if (b)
    d = extgcd(b, a % b, y, x), y -= (a / b) * x;
  else
    x = 1, y = 0;
  return d;
}
long long mod_inverse(long long a, long long m) {
  long long x, y;
  extgcd(a, m, x, y);
  return ((long long)m + x % m) % m;
}
long long r[R], s[R];
long long nCr[P + 2][P + 2];
vector<long long> mul(vector<long long>& a, vector<long long>& b) {
  int n = ((int)(a).size()) - 1, m = ((int)(b).size()) - 1;
  vector<long long> res(n + m + 1);
  for (int i = 0; i < (n + 1); i++)
    for (int j = 0; j < (m + 1); j++) {
      res[i + j] += a[i] * b[j] % 10007LL;
    }
  for (int i = 0; i < (((int)(res).size())); i++) {
    res[i] %= 10007LL;
  }
  return res;
}
long long mod_pow(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % 10007LL;
    x = x * x % 10007LL;
    n >>= 1;
  }
  return res;
}
int offset;
long long p24[P + 1], p25[P + 1], p26[P + 1];
vector<long long> a[R][P + 2];
long long b[R][P + 2];
long long p[P + 2][P + 2];
vector<long long> c[P + 2];
int n, l;
string str;
int dp[P][P][P + 1];
int f(int left, int right, int n24) {
  int& res = dp[left][right][n24];
  if (res != -1) return res;
  res = 0;
  if (left == right) {
    if (n24 == 0) res = 1;
  } else {
    if (str[left] == str[right]) {
      if (left + 1 == right) {
        if (n24 == 0) res = 1;
      } else {
        res = f(left + 1, right - 1, n24);
      }
    } else {
      if (n24 > 0) {
        res = f(left + 1, right, n24 - 1) + f(left, right - 1, n24 - 1);
      }
    }
  }
  return res %= 10007LL;
}
int calc(int n0, int n1, int n2) {
  long long p[P + 1] = {}, pc = 0;
  long long pn0[P + 1] = {1};
  for (int i = 0; i < (l); i++) pn0[i + 1] = pn0[i] * n0 % 10007LL;
  for (int i = 0; i < (n2); i++) {
    for (int j = 0; j < (i + 1); j++) {
      p[j] += c[n2 - 1][i] * a[0][i][j];
    }
    pc += c[n2 - 1][i] * b[0][i];
  }
  for (int i = 0; i < (n2); i++) {
    p[i] %= 10007LL;
  }
  pc %= 10007LL;
  if (n1 == 0) {
    long long res = pc * p26[n0 - offset];
    for (int i = 0; i < (n2); i++) {
      res += p[i] * pn0[i] * p25[n0 - offset];
    }
    return res * invfact[n2 - 1] % 10007LL;
  }
  vector<long long> q(n2);
  for (int i = 0; i < (n2); i++) {
    for (int j = 0; j < (i + 1); j++) {
      q[j] += nCr[i][j] * p[i] * pn0[i - j] * (j % 2 ? (10007LL - 1) : 1);
    }
  }
  for (int i = 0; i < (n2); i++) {
    q[i] %= 10007LL;
  }
  long long d[P + 1] = {}, dc = 0;
  for (int i = 0; i < (n1); i++) {
    for (int j = 0; j < (i + 1); j++) {
      d[j] += c[n1 - 1][i] * a[1][i][j];
    }
    dc += c[n1 - 1][i] * b[1][i];
  }
  for (int i = 0; i < (n1); i++) {
    d[i] %= 10007LL;
  }
  dc %= 10007LL;
  long long res1 = dc * p26[n0 - offset];
  for (int i = 0; i < (n1); i++) {
    res1 += d[i] * pn0[i] * p24[n0 - offset];
  }
  res1 %= 10007LL;
  q = mul(q, c[n1 - 1]);
  long long e[P + 1] = {}, ec = 0;
  for (int i = 0; i < (((int)(q).size())); i++) {
    for (int j = 0; j < (i + 1); j++) {
      e[j] += q[i] * a[2][i][j];
    }
    ec += q[i] * b[2][i];
  }
  for (int i = 0; i < (((int)(q).size())); i++) {
    e[i] %= 10007LL;
  }
  ec %= 10007LL;
  long long res2 = ec * p25[n0 - offset];
  for (int i = 0; i < (((int)(q).size())); i++) {
    res2 += e[i] * pn0[i] * p24[n0 - offset] % 10007LL;
  }
  return (res1 * pc + res2) * invfact[n1 - 1] * invfact[n2 - 1] % 10007LL;
}
long long calc2(int n0, int n1, int n2) {
  if (n1 == 0) {
    long long res = p25[n0 - offset];
    for (int i = 0; i < (n2 - 1); i++) {
      res = res * (n0 + i + 1) % 10007LL;
    }
    return res * invfact[n2 - 1] % 10007LL;
  }
  long long p[P + 1] = {}, pc = 0;
  long long pn0[P + 1] = {1};
  for (int i = 0; i < (l); i++) pn0[i + 1] = pn0[i] * n0 % 10007LL;
  vector<long long> v = c[n1 - 1];
  for (int i = 0; i < (n2 - 1); i++) {
    vector<long long> w{n0 + i + 1, 10007LL - 1};
    v = mul(v, w);
  }
  for (int i = 0; i < (((int)(v).size())); i++) {
    for (int j = 0; j < (i + 1); j++) {
      p[j] += v[i] * a[2][i][j];
    }
    pc += v[i] * b[2][i];
  }
  for (int i = 0; i < (((int)(v).size())); i++) {
    p[i] %= 10007LL;
  }
  pc %= 10007LL;
  long long res = pc * p25[n0 - offset];
  for (int i = 0; i < (((int)(v).size())); i++) {
    res += p[i] * pn0[i] * p24[n0 - offset] % 10007LL;
  }
  return res * invfact[n1 - 1] * invfact[n2 - 1] % 10007LL;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> str >> n;
  l = ((int)(str).size());
  n += l;
  int m = (n + 1) / 2;
  getinv(P + 1);
  invfact[0] = 1;
  for (int i = 0; i < (P); i++)
    invfact[i + 1] = invfact[i] * inv[i + 1] % 10007LL;
  r[0] = 25 * inv[26] % 10007LL;
  r[1] = 24 * inv[26] % 10007LL;
  r[2] = 24 * inv[25] % 10007LL;
  for (int i = 0; i < (R); i++) {
    s[i] = mod_inverse(r[i] - 1, 10007LL);
  }
  for (int i = 0; i < (P + 2); i++)
    for (int j = 0; j < (i + 1); j++) {
      if (j == 0 || j == i)
        nCr[i][j] = 1;
      else
        nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % 10007LL;
    }
  offset = max(0, m - l);
  p24[0] = mod_pow(24, offset);
  p25[0] = mod_pow(25, offset);
  p26[0] = mod_pow(26, offset);
  for (int j = 0; j < (P); j++) {
    p24[j + 1] = p24[j] * 24 % 10007LL;
    p25[j + 1] = p25[j] * 25 % 10007LL;
    p26[j + 1] = p26[j] * 26 % 10007LL;
  }
  for (int I = 0; I < (R); I++) {
    a[I][0].resize(1);
    a[I][0][0] = r[I] * s[I] % 10007LL;
    b[I][0] = (10007LL - 1) * s[I] % 10007LL;
    for (int i = 1; i < (P + 1); i++) {
      a[I][i].clear();
      b[I][i] = 0;
      a[I][i].resize(i + 1);
      a[I][i][i] = r[I];
      for (int j = 0; j < (i); j++) {
        for (int k = 0; k < (j + 1); k++) {
          a[I][i][k] +=
              ((i - j) % 2 ? 10007LL - a[I][j][k] : a[I][j][k]) * nCr[i][j];
        }
        b[I][i] += ((i - j) % 2 ? 10007LL - b[I][j] + (j == 0)
                                : b[I][j] + 10007LL - (j == 0)) *
                   nCr[i][j];
      }
      for (int j = 0; j < (i + 1); j++) {
        a[I][i][j] = a[I][i][j] * s[I] % 10007LL;
      }
      b[I][i] = b[I][i] * s[I] % 10007LL;
    }
  }
  c[0].resize(1);
  c[0][0] = 1;
  for (int i = 1; i < (P + 1); i++) {
    vector<long long> v{i, 1};
    c[i] = mul(c[i - 1], v);
  }
  memset(dp, -1, sizeof(dp));
  long long ans = 0;
  for (int n24 = 0; n24 < (l); n24++) {
    int n25 = (l - n24 + 1) / 2;
    bool last25_double = (l - n24) % 2 == 0;
    int n26 = m - n24 - n25;
    if (n26 < 0) continue;
    int ways = f(0, l - 1, n24);
    ans += ways * calc(n26, n24, n25);
    if (n % 2 == 1 && last25_double) {
      ans += 10007LL * 10007LL - ways * calc2(n26, n24, n25);
    }
  }
  cout << ans % 10007LL << endl;
}
