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 N = 205;
const int MOD = 10007;
int n, m, p, f[N * N][N], ans, k;
bool vis[N * N];
char s[N];
struct Matrix {
  int a[N << 1][N << 1];
} mt;
vector<int> g[N * N];
Matrix operator*(Matrix a, Matrix b) {
  Matrix rs;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) rs.a[i][j] = 0;
  for (int i = 0; i < n; ++i)
    for (int k = i; k < n; ++k)
      for (int j = k; j < n; ++j)
        rs.a[i][j] = (rs.a[i][j] + a.a[i][k] * b.a[k][j]) % MOD;
  return rs;
}
Matrix fpow(Matrix x, int p) {
  Matrix rs;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) rs.a[i][j] = i == j ? 1 : 0;
  while (p) {
    if (p & 1) rs = rs * x;
    x = x * x;
    p >>= 1;
  }
  return rs;
}
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = true;
  int l = u / m, r = u % m;
  for (auto v : g[u]) dfs(v);
  if (u == m * m || s[l] == s[r]) {
    for (auto v : g[u])
      for (int o = 0; o <= m; ++o) f[u][o] += f[v][o];
    for (int o = 0; o <= m; ++o) f[u][o] %= MOD;
  } else {
    for (auto v : g[u])
      for (int o = 1; o <= m; ++o) f[u][o] += f[v][o - 1];
    for (int o = 1; o <= m; ++o) f[u][o] %= MOD;
  }
}
int main() {
  scanf("%s", s);
  scanf("%d", &p);
  m = strlen(s);
  k = (m + 1) >> 1;
  n = m + (k << 1) + 1;
  for (int i = 0; i < m; ++i) {
    for (int j = i; j < m; ++j) {
      if (s[i] == s[j]) {
        if (j - i + 1 <= 2)
          g[m * m].push_back(i * m + j);
        else
          g[(i + 1) * m + j - 1].push_back(i * m + j);
      } else {
        g[(i + 1) * m + j].push_back(i * m + j);
        g[i * m + j - 1].push_back(i * m + j);
      }
    }
  }
  vis[m - 1] = true;
  f[m - 1][s[0] != s[m - 1]] = 1;
  for (int i = 0; i < m; ++i) dfs(i * m + i);
  dfs(m * m);
  memset(mt.a, 0, sizeof(mt.a));
  for (int i = 0; i < m; ++i) {
    if (i) mt.a[i - 1][i] = 1;
    mt.a[i][i] = 24;
  }
  for (int i = 0; i < k; ++i) {
    mt.a[i - 1 + m][i + m] = 1;
    mt.a[i + m][i + m] = 25;
  }
  for (int i = 0; i <= k; ++i) {
    mt.a[i - 1 + m][i + m + k] = 1;
    mt.a[i + m + k][i + m + k] = 26;
  }
  mt = fpow(mt, ((p + m) >> 1));
  for (int i = 0; i <= m; ++i) {
    ans = (ans + f[m * m][i] * mt.a[m - i][((m - i + 1) >> 1) + m + k]) % MOD;
  }
  if ((m + p) & 1) {
    ans = ans * 26 % MOD;
    for (int o = 0; o < m; ++o) {
      for (int i = 0; i <= m - 1; ++i) {
        ans = (ans + f[o * m + o][i] * mt.a[m - i][((m - i) >> 1) + m]) % MOD;
      }
    }
  }
  printf("%d\n", ans);
}