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>
const int N = 200;
const int MOD = 10007;
void add(int &x, int a) {
  x += a;
  if (x >= MOD) {
    x -= MOD;
  }
}
static int pow(int a, int n) {
  a %= MOD;
  int result = 1;
  while (n) {
    if (n & 1) {
      result = result * a % MOD;
    }
    a = a * a % MOD;
    n >>= 1;
  }
  return result;
}
static int inv(int a) { return pow(a, MOD - 2); }
static int neg(int n) { return n & 1 ? MOD - 1 : 1; }
struct Binom {
  Binom(int m)
      : binom(m + 1, std::vector<int>(m + 1)),
        coef(m + 1, std::vector<int>(m + 1)) {
    for (int i = 0; i <= m; ++i) {
      binom[i][0] = 1;
      for (int j = 1; j <= i; ++j) {
        binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % MOD;
      }
    }
    coef[1][0] = 1;
    for (int k = 1; k < m; ++k) {
      int invk = inv(k);
      coef[k][0] = 1;
      for (int i = k; i >= 1; --i) {
        coef[k + 1][i] = (coef[k][i - 1] + coef[k][i] * k) % MOD * invk % MOD;
      }
    }
  }
  const int *operator[](int i) const { return binom[i].data(); }
  std::vector<std::vector<int>> binom, coef;
};
struct Evalution {
  Evalution(const Binom &binom_, int q_, int m, bool skip = false)
      : binom(binom_), q(q_), co(m + 1), scoef(m + 1, std::vector<int>(m + 1)) {
    const int invq = inv(1 + MOD - q);
    std::vector<int> psco(m + 1);
    std::vector<std::vector<int>> pscoef(m + 1, std::vector<int>(m + 1));
    psco[0] = invq;
    pscoef[0] = {MOD - invq};
    for (int k = 1; k <= m; ++k) {
      psco[k] = neg(k);
      for (int i = 0; i < k; ++i) {
        const int factor = binom[k][i] * neg(k - i + 1) % MOD;
        add(psco[k], factor * psco[i] % MOD);
        for (int j = 0; j <= i; ++j) {
          add(pscoef[k][j], factor * pscoef[i][j] % MOD);
        }
      }
      pscoef[k][k] = MOD - 1;
      psco[k] = psco[k] * invq % MOD;
      for (int i = 0; i <= k; ++i) {
        pscoef[k][i] = pscoef[k][i] * invq % MOD;
      }
    }
    if (skip) {
      co = psco;
      scoef = pscoef;
    } else {
      for (int k = 1; k <= m; ++k) {
        for (int i = 0; i < k; ++i) {
          add(co[k], binom.coef[k][i] * psco[i] % MOD);
          for (int j = 0; j <= i; ++j) {
            add(scoef[k][j], binom.coef[k][i] * pscoef[i][j] % MOD);
          }
        }
      }
    }
  }
  int get(int n, int k) {
    int result = 0;
    for (int i = k; i >= 0; --i) {
      result = (1LL * result * n + scoef[k][i]) % MOD;
    }
    return (co[k] + pow(q, n + 1) * result) % MOD;
  }
  std::vector<int> plugin(int n, int k) {
    n %= MOD;
    std::vector<int> coef(k + 1);
    for (int j = 0; j <= k; ++j) {
      int pown = 1;
      for (int i = j; i <= k; ++i) {
        add(coef[j], scoef[k][i] * binom[i][j] % MOD * pown % MOD);
        pown = pown * n % MOD;
      }
      coef[j] = neg(j) * coef[j] % MOD;
    }
    return coef;
  }
  const Binom &binom;
  int q;
  std::vector<int> co;
  std::vector<std::vector<int>> scoef;
};
struct Solver {
  Solver(int m, int ym)
      : binom{m + ym},
        xeval{binom, 24 * inv(26) % MOD, m},
        yeval{binom, 25 * inv(26) % MOD, ym},
        xyeval{binom, 24 * inv(25) % MOD, m + ym, true} {}
  int solve(int n, int a, int b) {
    if (a + b > n) {
      return 0;
    }
    n -= a + b;
    int result = 0;
    if (a == 0) {
      if (b == 0) {
        result = 1;
      } else {
        result = yeval.get(n, b);
      }
    } else {
      if (b == 0) {
        result = xeval.get(n, a);
      } else {
        auto ycoef = yeval.plugin(n, b);
        std::vector<int> zcoef(a + b + 1);
        for (int i = 0; i <= a; ++i) {
          for (int j = 0; j <= b; ++j) {
            add(zcoef[i + j], binom.coef[a][i] * ycoef[j] % MOD);
          }
        }
        for (int i = 0; i <= a + b; ++i) {
          add(result, zcoef[i] * xyeval.get(n, i) % MOD);
        }
        result = result * pow(yeval.q, n + 1) % MOD;
        add(result, xeval.get(n, a) * yeval.co[b] % MOD);
      }
    }
    return result * pow(26, n) % MOD;
  }
  Binom binom;
  Evalution xeval, yeval, xyeval;
};
int main() {
  std::string s;
  int n;
  std::cin >> s >> n;
  int m = s.length();
  n += m;
  int max_simu = (m + 1) >> 1;
  std::vector<std::vector<std::vector<int>>> dp(
      m + 1,
      std::vector<std::vector<int>>(m + 1, std::vector<int>(max_simu + 1)));
  dp[0][m][0] = 1;
  for (int i = 0; i < m; ++i) {
    for (int j = m; j > i; --j) {
      if (s[i] == s[j - 1]) {
        for (int simu = 0; simu < max_simu; ++simu) {
          add(dp[i + 1][j - 1][simu + 1], dp[i][j][simu]);
        }
      } else {
        for (int simu = 0; simu <= max_simu; ++simu) {
          add(dp[i + 1][j][simu], dp[i][j][simu]);
          add(dp[i][j - 1][simu], dp[i][j][simu]);
        }
      }
    }
  }
  int result = 0;
  int half = (n + 1) >> 1;
  Solver solver{m + 1, max_simu};
  for (int c25 = 0; c25 <= max_simu; ++c25) {
    {
      int c24 = m - 2 * c25;
      if (c24 >= 0) {
        int count = 0;
        for (int i = 0; i <= m; ++i) {
          add(count, dp[i][i][c25]);
        }
        if (n & 1) {
          add(result, 26LL * count * solver.solve(half - 1, c24, c25) % MOD);
        } else {
          add(result, count * solver.solve(half, c24, c25) % MOD);
        }
      }
    }
    {
      int c24 = m + 1 - 2 * c25;
      int count = 0;
      for (int i = 1; i <= m; ++i) {
        add(count, dp[i][i - 1][c25]);
      }
      add(result, count * solver.solve(half, c24, c25) % MOD);
    }
  }
  printf("%d\n", result);
}