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 INF = 0x3f3f3f3f;
const long long llINF = 1e18;
const int MAXN = 405;
const int MOD = 1e4 + 7;
void addmod(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
void submod(int &x, int y) {
  x -= y;
  if (x < 0) x += MOD;
}
int add(int x, int y) {
  addmod(x, y);
  return x;
}
int sub(int x, int y) {
  submod(x, y);
  return x;
}
int n, m, N, ans;
int h[MAXN][MAXN][MAXN], sum[MAXN];
char s[MAXN];
struct Matrix {
  int a[MAXN][MAXN];
  Matrix(bool flag = 0) {
    memset(a, 0, sizeof(a));
    if (!flag) return;
    for (int i = 0; i <= N; i++) a[i][i] = 1;
  }
  int *operator[](const int &x) { return a[x]; }
  const int *operator[](const int &x) const { return a[x]; }
  Matrix operator*(const Matrix &rhs) const {
    Matrix res;
    for (int i = 0; i <= N; i++) {
      for (int k = i; k <= N; k++) {
        for (int j = k; j <= N; j++)
          addmod(res[i][j], 1ll * a[i][k] * rhs[k][j] % MOD);
      }
    }
    return res;
  }
  Matrix operator^(int y) const {
    Matrix res(1);
    Matrix x = *this;
    while (y) {
      if (y & 1) res = res * x;
      x = x * x;
      y >>= 1;
    }
    return res;
  }
  void print() {
    for (int i = 0; i <= N; i++) {
      for (int j = 0; j <= N; j++) cout << a[i][j] << " ";
      cout << endl;
    }
    cout << endl;
  }
} A;
int GetH(int l, int r, int i) {
  if (i < 0) return 0;
  if (h[l][r][i] != -1) return h[l][r][i];
  h[l][r][i] = 0;
  if (l == 1 && r == n) return h[l][r][i] = (i == 0);
  if (l != 1 && r != n && s[l - 1] == s[r + 1])
    addmod(h[l][r][i], GetH(l - 1, r + 1, i));
  if (l != 1 && s[l - 1] != s[r]) addmod(h[l][r][i], GetH(l - 1, r, i - 1));
  if (r != n && s[r + 1] != s[l]) addmod(h[l][r][i], GetH(l, r + 1, i - 1));
  return h[l][r][i];
}
int main() {
  memset(h, -1, sizeof(h));
  scanf("%s", s + 1);
  scanf("%d", &m);
  n = strlen(s + 1);
  for (int i = 0; i < n; i++) {
    sum[i] = GetH(1, 1, i);
    for (int j = 2; j <= n; j++) {
      if (s[j - 1] == s[j]) addmod(sum[i], GetH(j - 1, j, i));
      addmod(sum[i], GetH(j, j, i));
    }
  }
  N = n + (n + 1) / 2 + 1;
  for (int i = 1; i <= n; i++) {
    A[i][i] = 24;
    A[i][N - (n - i + 1) / 2] = sum[i];
    if (i != n) A[i][i + 1] = 1;
  }
  for (int i = n + 1; i < N; i++) A[i][i + 1] = 1, A[i][i] = 25;
  A[N][N] = 26;
  if ((n + m) & 1) {
    A = A ^ ((n + m + 1) >> 1);
    ans = add(A[1][N], 1ll * sum[0] * A[n + 1][N] % MOD);
    A = Matrix();
    memset(sum, 0, sizeof(sum));
    for (int i = 0; i < n; i++) {
      if (s[i] != s[i + 1]) continue;
      for (int j = 0; j <= n; j++) addmod(sum[j], GetH(i, i + 1, j));
    }
    for (int i = 1; i <= n; i++) {
      A[i][i] = 24;
      A[i][N - (n - i + 1) / 2] = sum[i];
      if (i != n) A[i][i + 1] = 1;
    }
    for (int i = n + 1; i < N; i++) A[i][i + 1] = 1, A[i][i] = 25;
    A = A ^ ((n + m + 1) >> 1);
    submod(ans, add(A[1][N], 1ll * sum[0] * A[n + 1][N] % MOD));
  } else {
    A = A ^ ((n + m) >> 1);
    ans = add(A[1][N], 1ll * sum[0] * A[n + 1][N] % MOD);
  }
  printf("%d\n", ans);
  return 0;
}