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>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MAX = 1e5 + 5;
const long long MAX2 = 11;
const long long MOD = 10007;
const long long MOD2 = 1000005329;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 555;
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 = 0;
    for (int j = 0; j < int(cur.size()); ++j)
      t = (t + x[i - j - 1] * (long long)cur[j]) % MOD;
    if ((t - x[i]) % MOD == 0) continue;
    if (!cur.size()) {
      cur.resize(i + 1);
      lf = i;
      ld = (t - x[i]) % MOD;
      continue;
    }
    long long k = -(x[i] - 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 - x[i]) % MOD;
    cur = c;
  }
  for (int i = 0; i < int(cur.size()); ++i) cur[i] = (cur[i] % MOD + MOD) % MOD;
  return cur;
}
int m;
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 < m + m; ++i) t_[i] = 0;
  for (int i = 0; i < m; ++i)
    if (p[i])
      for (int j = 0; j < m; ++j) t_[i + j] = (t_[i + j] + p[i] * q[j]) % MOD;
  for (int i = m + m - 1; i >= m; --i)
    if (t_[i])
      for (int j = m - 1; ~j; --j)
        t_[i - j - 1] = (t_[i - j - 1] + t_[i] * h[j]) % MOD;
  for (int i = 0; i < m; ++i) p[i] = t_[i];
}
inline long long calc(long long K) {
  for (int i = m; ~i; --i) s[i] = t[i] = 0;
  s[0] = 1;
  if (m != 1)
    t[1] = 1;
  else
    t[0] = h[0];
  while (K) {
    if (K & 1) mull(s, t);
    mull(t, t);
    K >>= 1;
  }
  long long su = 0;
  for (int i = 0; i < m; ++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);
  m = v.size();
  if (!m) return 0;
  for (int i = 0; i < m; ++i) h[i] = v[i], a[i] = x[i];
  return calc(n);
}
}  // namespace linear_seq
using linear_seq::work;
int n, dp[1005][201][201], sta;
bool st;
string s;
vector<int> sq;
int f(int rem, int le, int ri) {
  if (!rem) return le > ri;
  if (ri < 0) ri = 0;
  int &ret = dp[rem][le][ri];
  if (ret != -1) return ret;
  if (le > ri) return ret = 26 * f(rem - 1, le, ri) % MOD;
  if (rem == 1 && st && le != ri) return ret = 0;
  if (s[le] == s[ri])
    ret = (25 * f(rem - 1, le, ri) + f(rem - 1, le + 1, ri - 1)) % MOD;
  else
    ret = ret = (24 * f(rem - 1, le, ri) + f(rem - 1, le, ri - 1) +
                 f(rem - 1, le + 1, ri)) %
                MOD;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> n;
  if ((n + s.size()) & 1) st = 1;
  memset(dp, -1, sizeof dp);
  sta = s.size();
  if (n & 1) ++sta;
  sta = (sta + 1) / 2;
  for (int i = 0; i <= 900; ++i) sq.push_back(f(sta + i, 0, s.size() - 1));
  cout << work(sq, n / 2) << '\n';
  return 0;
}