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("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using db = long double;
using row = vector<int>;
using ii = pair<int, int>;
const int N = 3e5 + 5, M = 1e6 + 5, A = 6561, LG = 17, MOD = 1e4 + 7;
const int BLOCK = 1900;
const int BLOCKN = N / BLOCK + 1;
const long double EPS = 1e-7;
ll fast(ll x, ll p) {
  ll ret = 1;
  for (; p; p >>= 1, x = x * x % MOD)
    if (p & 1) ret = ret * x % MOD;
  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++) {
    ll 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;
    }
    ll k = -(x[i] - t) * fast(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, ll 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;
  }
  ll 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, ll 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], n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s >> n;
  dp[0][0][s.size()] = 1;
  vector<int> v;
  for (int i = 0; i < 1501; i++) {
    for (int j = 0; j < s.size() + 1; j++)
      for (int k = j; k < s.size() + 1; 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;
        }
      }
    ll sum = 0;
    for (int j = 0; j < s.size() + 1; j++) {
      sum += dp[i][j][j];
      if (j) sum += dp[i][j - 1][j];
      if (i) sum += dp[i - 1][j][j] * 26;
    }
    v.push_back(sum % MOD);
  }
  cout << linear_seq::guess_nth_term(v, n) << '\n';
  return 0;
}