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;
using vint = vector<long long>;
using pint = pair<long long, long long>;
using vpint = vector<pint>;
template <typename A, typename B>
inline void chmin(A& a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A& a, B b) {
  if (a < b) a = b;
}
template <class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
  ost << "{" << p.first << "," << p.second << "}";
  return ost;
}
template <class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
  ost << "{";
  for (long long i = 0; i < v.size(); i++) {
    if (i) ost << ",";
    ost << v[i];
  }
  ost << "}";
  return ost;
}
inline long long topbit(unsigned long long x) {
  return x ? 63 - __builtin_clzll(x) : -1;
}
inline long long popcount(unsigned long long x) {
  return __builtin_popcountll(x);
}
inline long long parity(unsigned long long x) { return __builtin_parity(x); }
template <uint32_t mod>
struct ModInt {
  uint32_t a;
  ModInt& s(uint32_t vv) {
    a = vv < mod ? vv : vv - mod;
    return *this;
  }
  ModInt(int64_t x = 0) { s(x % mod + mod); }
  ModInt& operator+=(const ModInt& x) { return s(a + x.a); }
  ModInt& operator-=(const ModInt& x) { return s(a + mod - x.a); }
  ModInt& operator*=(const ModInt& x) {
    a = uint64_t(a) * x.a % mod;
    return *this;
  }
  ModInt& operator/=(const ModInt& x) {
    *this *= x.inv();
    return *this;
  }
  ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
  ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
  ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
  ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
  bool operator==(const ModInt& x) const { return a == x.a; }
  bool operator!=(const ModInt& x) const { return a != x.a; }
  bool operator<(const ModInt& x) const { return a < x.a; }
  ModInt operator-() const { return ModInt() - *this; }
  ModInt pow(int64_t n) const {
    ModInt res(1), x(*this);
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  ModInt inv() const { return pow(mod - 2); }
};
template <uint32_t mod>
istream& operator>>(istream& in, ModInt<mod>& a) {
  return (in >> a.a);
}
template <uint32_t mod>
ostream& operator<<(ostream& out, const ModInt<mod>& a) {
  return (out << a.a);
}
using mint = ModInt<10007>;
using mat = vector<vector<mint>>;
string S;
long long N;
mint dp[210][210][210];
mat matmul(const mat& A, const mat& B) {
  mat C(A.size(), vector<mint>(A.size()));
  for (long long i = 0; i < A.size(); i++) {
    for (long long j = i; j < A.size(); j++) {
      for (long long k = i; k <= j; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  return C;
}
mat matpow(mat A, long long k) {
  mat ret(A.size(), vector<mint>(A.size()));
  for (long long i = 0; i < (A.size()); i++) ret[i][i] = 1;
  while (k) {
    if (k & 1) ret = matmul(ret, A);
    A = matmul(A, A);
    k >>= 1;
  }
  return ret;
}
signed main() {
  cin >> S >> N;
  N += S.size();
  for (long long i = 0; i < (S.size()); i++) dp[0][i][i] = 1;
  for (long long i = 0; i < (S.size()); i++) dp[0][i][i + 1] = 1;
  for (long long i = S.size() - 1; i >= 0; i--) {
    for (long long j = i + 2; j <= S.size(); j++) {
      for (long long k = 0; k < S.size(); k++) {
        if (S[i] == S[j - 1]) {
          dp[k][i][j] += dp[k][i + 1][j - 1];
        } else {
          if (k == 0) continue;
          dp[k][i][j] += dp[k - 1][i + 1][j];
          dp[k][i][j] += dp[k - 1][i][j - 1];
        }
      }
    }
  }
  const long long X = S.size();
  const long long Y = (S.size() + 1) / 2;
  const long long Z = Y;
  vector<vector<mint>> A(X + Y + Z, vector<mint>(X + Y + Z));
  for (long long i = 0; i < (X); i++) {
    A[i][i] = 24;
    A[i][i + 1] = 1;
  }
  for (long long i = 0; i < (Y); i++) {
    A[X + i][X + i] = 25;
    if (i + 1 < Y) A[X + i][X + i + 1] = 1;
    A[X + i][X + Y + i] = 1;
  }
  for (long long i = 0; i < (Z); i++) {
    A[X + Y + i][X + Y + i] = 26;
  }
  mat C = matpow(A, (N + 1) / 2 - 1);
  A = matmul(C, A);
  mint ans = 0;
  for (long long k = 0; k < S.size(); k++) {
    long long l = (S.size() - k + 1) / 2;
    ans += dp[k][0][S.size()] * A[X - k][X + Y + l - 1];
    if ((S.size() - k) % 2 == 0 && N % 2) {
      ans -= dp[k][0][S.size()] * C[X - k][X + l - 1];
    }
  }
  cout << ans << endl;
  return 0;
}
