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 INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 207;
const int MAXS = 2007;
const int MOD = 10007;
int m;
int b[MAXS];
struct pT {
  pT() { clear(); }
  void clear() { memset(a, 0, sizeof(a)); }
  int operator[](int i) const { return a[i]; }
  int &operator[](int i) { return a[i]; }
  pT operator*(const pT &x) const {
    pT ans;
    for (int i = 0; i < m; ++i)
      for (int j = 0; j < m; ++j) (ans[i + j] += a[i] * x[j]) %= MOD;
    for (int i = m * 2 - 2; i >= m; --i) {
      for (int j = 1; j <= m; ++j) (ans[i - j] += ans[i] * b[j]) %= MOD;
      ans[i] = 0;
    }
    return ans;
  }
  void operator*=(const pT &x) { (*this) = (*this) * x; }
  int a[MAXS * 2];
};
int n, K;
char s[MAXN];
int a[MAXS], pb[MAXS], tc[MAXS];
int dp[2][MAXN][MAXN];
void init();
void input();
void work();
pT qpow(const pT &a, int b) {
  pT base = a, ans;
  ans[0] = 1;
  while (b) {
    if (b & 1) ans *= base;
    base *= base;
    b >>= 1;
  }
  return ans;
}
int add(int x, int y) { return ((x += y) < MOD) ? x : (x - MOD); }
void addv(int &x, int y) { ((x += y) < MOD) ? x : (x -= MOD); }
int sub(int x, int y) { return ((x -= y) >= 0) ? x : (x + MOD); }
void subv(int &x, int y) { ((x -= y) >= 0) ? x : (x += MOD); }
int qpow(int a, int b) {
  long long base = a, ans = 1;
  while (b) {
    if (b & 1) (ans *= base) %= MOD;
    (base *= base) %= MOD;
    b >>= 1;
  }
  return static_cast<int>(ans);
}
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() { scanf("%s%d", s + 1, &K); }
void work() {
  n = strlen(s + 1);
  bool tp = (n + K) & 1;
  int t = 0;
  dp[t][1][n] = 1;
  for (int i = -(n >> 1); i < MAXS; ++i) {
    if (i >= 0) {
      if (!tp)
        for (int j = 1; j <= n + 1; ++j)
          for (int k = 0; k < j; ++k) addv(a[i], dp[t][j][k]);
      else
        for (int j = 1; j <= n + 1; ++j)
          for (int k = 0; k <= j; ++k)
            (a[i] += dp[t][j][k] * ((j ^ k) ? 26 : 1)) %= MOD;
    }
    t ^= 1;
    memset(dp[t], 0, sizeof(dp[t]));
    for (int j = 1; j <= n + 1; ++j) {
      for (int k = 0; k <= n; ++k) {
        if (j == n + 1 || !k) {
          (dp[t][j][k] += dp[t ^ 1][j][k] * 26) %= MOD;
        } else if (s[j] == s[k]) {
          addv(dp[t][j + 1][k - 1], dp[t ^ 1][j][k]);
          (dp[t][j][k] += dp[t ^ 1][j][k] * 25) %= MOD;
        } else {
          addv(dp[t][j + 1][k], dp[t ^ 1][j][k]);
          addv(dp[t][j][k - 1], dp[t ^ 1][j][k]);
          (dp[t][j][k] += dp[t ^ 1][j][k] * 24) %= MOD;
        }
      }
    }
  }
  pb[1] = 0;
  b[1] = a[1] * qpow(a[0], MOD - 2) % MOD;
  m = 1;
  int pre = 1, pm = 1, tm, cv, tv, coef;
  for (int i = 2; i < MAXS; ++i) {
    cv = 0;
    for (int j = 1; j <= m; ++j) (cv += b[j] * a[i - j]) %= MOD;
    if (cv ^ a[i]) {
      tv = 0;
      for (int j = 1; j <= m; ++j) tc[1] = 1;
      for (int j = 1; j <= pm; ++j) tc[j + 1] = sub(0, pb[j]);
      for (int j = pm + 1; j >= 0; --j) tc[j + (i - pre - 1)] = tc[j];
      tm = (pm + 1) + (i - pre - 1);
      for (int j = 0; j < i - pre - 1; ++j) tc[j] = 0;
      tv = 0;
      for (int j = 1; j <= pm; ++j) (tv += pb[j] * a[pre - j]) %= MOD;
      coef = sub(cv, a[i]) * qpow(sub(tv, a[pre]), MOD - 2) % MOD;
      pm = m;
      for (int j = 1; j <= pm; ++j) pb[j] = b[j];
      pre = i;
      m = (((m) > (tm)) ? (m) : (tm));
      for (int j = 1; j <= m; ++j) (b[j] += tc[j] * coef) %= MOD;
    }
  }
  pT bs;
  bs[1] = 1;
  pT ret = qpow(bs, ((K + n) >> 1) - (n >> 1));
  int ans = 0;
  for (int i = 0; i < m; ++i) (ans += ret[i] * a[i]) %= MOD;
  cout << ans << endl;
}