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 MOD = 1e4 + 7;
long long qp(long long a, long long b) {
  long long x = 1;
  a %= MOD;
  while (b) {
    if (b & 1) x = x * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return x;
}
namespace linear_seq {
inline vector<int> BM(vector<int> x) {
  vector<int> ls, cur;
  int lf, ld;
  for (int i = 0; i < int(x.size()); ++i) {
    long long t = -x[i] % MOD;
    for (int j = 0; j < int(cur.size()); ++j)
      t = (t + x[i - j - 1] * (long long)cur[j]) % MOD;
    if (!t) continue;
    if (!cur.size()) {
      cur.resize(i + 1);
      lf = i;
      ld = t;
      continue;
    }
    long long k = -t * qp(ld, MOD - 2) % MOD;
    vector<int> c(i - lf - 1);
    c.push_back(-k);
    for (int j = 0; j < int(ls.size()); ++j) c.push_back(ls[j] * k % MOD);
    if (c.size() < cur.size()) c.resize(cur.size());
    for (int j = 0; j < int(cur.size()); ++j) c[j] = (c[j] + cur[j]) % MOD;
    if (i - lf + (int)ls.size() >= (int)cur.size()) ls = cur, lf = i, ld = t;
    cur = c;
  }
  vector<int>& o = cur;
  for (int i = 0; i < int(o.size()); ++i) o[i] = (o[i] % MOD + MOD) % MOD;
  return o;
}
int N;
long long a[233333], h[233333], t_[233333], s[233333], t[233333];
inline void mull(long long* p, long long* q) {
  for (int i = 0; i < N + N; ++i) t_[i] = 0;
  for (int i = 0; i < N; ++i)
    if (p[i])
      for (int j = 0; j < N; ++j) t_[i + j] = (t_[i + j] + p[i] * q[j]) % MOD;
  for (int i = N + N - 1; i >= N; --i)
    if (t_[i])
      for (int j = N - 1; ~j; --j)
        t_[i - j - 1] = (t_[i - j - 1] + t_[i] * h[j]) % MOD;
  for (int i = 0; i < N; ++i) p[i] = t_[i];
}
inline long long calc(long long K) {
  for (int i = N; ~i; --i) s[i] = t[i] = 0;
  s[0] = 1;
  if (N != 1)
    t[1] = 1;
  else
    t[0] = h[0];
  for (; K; mull(t, t), K >>= 1)
    if (K & 1) mull(s, t);
  long long su = 0;
  for (int i = 0; i < N; ++i) su = (su + s[i] * a[i]) % MOD;
  return (su % MOD + MOD) % MOD;
}
inline int work(vector<int> x, long long n) {
  if (n < int(x.size())) return x[n];
  vector<int> v = BM(x);
  N = v.size();
  if (!N) return 0;
  for (int i = 0; i < N; ++i) h[i] = v[i], a[i] = x[i];
  return calc(n);
}
}  // namespace linear_seq
using linear_seq::work;
int dp[701][202][202], dp2[701][202][202];
string s;
int rec(int n, int i, int j) {
  if (n == 0) {
    if (i > j)
      return 1;
    else
      return 0;
  }
  if (dp[n][i][j] != -1) {
    return dp[n][i][j];
  }
  int an = 0;
  if (i > j) {
    an = an + rec(n - 1, i, j) * 26;
    an %= MOD;
  } else if (i == j) {
    an = an + rec(n - 1, i + 1, j) + rec(n - 1, i, j) * 25;
    an %= MOD;
  } else {
    if (s[i - 1] != s[j - 1])
      an = an + rec(n - 1, i + 1, j) + rec(n - 1, i, j - 1) +
           rec(n - 1, i, j) * 24;
    else
      an = an + rec(n - 1, i + 1, j - 1) + rec(n - 1, i, j) * 25;
    an %= MOD;
  }
  return dp[n][i][j] = an;
}
int rec2(int n, int i, int j) {
  if (n == 0) {
    if (i == j)
      return 1;
    else
      return 0;
  }
  if (dp2[n][i][j] != -1) {
    return dp2[n][i][j];
  }
  int an = 0;
  if (i > j) {
    an = an + rec2(n - 1, i, j) * 26;
    an %= MOD;
  } else if (i == j) {
    an = an + rec2(n - 1, i + 1, j) + rec2(n - 1, i, j) * 25;
    an %= MOD;
  } else {
    if (s[i - 1] != s[j - 1])
      an = an + rec2(n - 1, i + 1, j) + rec2(n - 1, i, j - 1) +
           rec2(n - 1, i, j) * 24;
    else
      an = an + rec2(n - 1, i + 1, j - 1) + rec2(n - 1, i, j) * 25;
    an %= MOD;
  }
  return dp2[n][i][j] = an;
}
int sum[10005];
int main() {
  vector<int> ans;
  string str;
  int n, n2;
  cin >> str;
  cin >> n;
  n2 = str.length();
  s = str;
  memset(dp, -1, sizeof(dp));
  memset(dp2, -1, sizeof(dp2));
  rec(701 - 1, 1, n2);
  rec2(701 - 1, 1, n2);
  ans.push_back(0);
  int i;
  for (i = 0; i <= 701 - 1; i++) {
    sum[i] = 0;
    for (int j = 1; j <= 201; j++) {
      if (dp[i][j][j - 1] != -1) {
        sum[i] += dp[i][j][j - 1];
        sum[i] %= MOD;
      }
    }
    sum[i] = 0;
    if (dp[i][1][n2] != -1) sum[i] = dp[i][1][n2];
  }
  for (i = 1; i < 2 * (701 - 2); i++) {
    if (i & 1) {
      if (dp2[i / 2][1][n2] != -1)
        ans.push_back(((sum[i / 2] * 26) % MOD + dp2[i / 2][1][n2]) % MOD);
      else
        ans.push_back((sum[i / 2] * 26) % MOD);
    } else
      ans.push_back(sum[i / 2]);
  }
  cout << work(ans, n + n2) << "\n";
}