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;
using pi = pair<int, int>;
using lint = long long;
const int mod = 1e4 + 7;
lint ipow(lint x, lint p) {
  lint ret = 1, piv = x;
  while (p) {
    if (p & 1) ret = ret * piv % mod;
    piv = piv * piv % mod;
    p >>= 1;
  }
  return ret;
}
namespace linear_seq {
vector<int> berlekamp_massey(vector<int> x) {
  vector<int> ls, cur;
  int lf, ld;
  for (int i = 0; i < x.size(); i++) {
    lint t = 0;
    for (int j = 0; j < cur.size(); j++) {
      t = (t + 1ll * x[i - j - 1] * cur[j]) % mod;
    }
    if ((t - x[i]) % mod == 0) continue;
    if (cur.empty()) {
      cur.resize(i + 1);
      lf = i;
      ld = (t - x[i]) % mod;
      continue;
    }
    lint k = -(x[i] - t) * ipow(ld, mod - 2) % mod;
    vector<int> c(i - lf - 1);
    c.push_back(k);
    for (auto &j : ls) c.push_back(-j * k % mod);
    if (c.size() < cur.size()) c.resize(cur.size());
    for (int j = 0; j < cur.size(); j++) {
      c[j] = (c[j] + cur[j]) % mod;
    }
    if (i - lf + (int)ls.size() >= (int)cur.size()) {
      tie(ls, lf, ld) = make_tuple(cur, i, (t - x[i]) % mod);
    }
    cur = c;
  }
  for (auto &i : cur) i = (i % mod + mod) % mod;
  return cur;
}
int get_nth(vector<int> rec, vector<int> dp, lint n) {
  int m = rec.size();
  vector<int> s(m), t(m);
  s[0] = 1;
  if (m != 1)
    t[1] = 1;
  else
    t[0] = rec[0];
  auto mul = [&rec](vector<int> v, vector<int> w) {
    int m = v.size();
    vector<int> t(2 * m);
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < m; k++) {
        t[j + k] += 1ll * v[j] * w[k] % mod;
        t[j + k] %= mod;
      }
    }
    for (int j = 2 * m - 1; j >= m; j--) {
      for (int k = 1; k <= m; k++) {
        t[j - k] += 1ll * t[j] * rec[k - 1] % mod;
        t[j - k] %= mod;
      }
    }
    t.resize(m);
    return t;
  };
  while (n) {
    if (n & 1) s = mul(s, t);
    t = mul(t, t);
    n >>= 1;
  }
  lint ret = 0;
  for (int i = 0; i < m; i++) ret += 1ll * s[i] * dp[i] % mod;
  return ret % mod;
}
int guess_nth_term(vector<int> x, lint n) {
  if (n < x.size()) return x[n];
  vector<int> v = berlekamp_massey(x);
  if (v.empty()) return 0;
  return get_nth(v, x, n);
}
}  // namespace linear_seq
string s;
int dp[1505][205][205];
int main() {
  int n;
  cin >> s >> n;
  dp[0][0][s.size()] = 1;
  vector<int> v;
  for (int i = 0; i <= 1500; i++) {
    for (int j = 0; j <= s.size(); j++) {
      for (int k = j; k <= s.size(); k++) {
        dp[i][j][k] %= mod;
        if (k - j >= 2) {
          if (s[j] == s[k - 1]) {
            dp[i][j + 1][k - 1] += dp[i][j][k];
            dp[i + 2][j][k] += dp[i][j][k] * 25;
          } else {
            dp[i + 1][j + 1][k] += dp[i][j][k];
            dp[i + 1][j][k - 1] += dp[i][j][k];
            dp[i + 2][j][k] += dp[i][j][k] * 24;
          }
        } else {
          if (k != j) {
            dp[i + 1][j + 1][k] += dp[i][j][k];
            dp[i + 2][j][k] += dp[i][j][k] * 25;
          } else
            dp[i + 2][j][k] += dp[i][j][k] * 26;
        }
      }
    }
    lint tmp = 0;
    for (int j = 0; j <= s.size(); j++) {
      tmp += dp[i][j][j];
      if (j) tmp += dp[i][j - 1][j];
      if (i) {
        tmp += dp[i - 1][j][j] * 26;
      }
    }
    v.push_back(tmp % mod);
  }
  cout << linear_seq::guess_nth_term(v, n) << endl;
}