#include <cstdio>
#include <cstring>

#define MAX 100
#define MOD 10007

int n,k;
char tip[MAX+1];
int memo_mix[MAX/2][MAX/2][MAX/2];
int helper(int a, int b, int c, int d);
int slovo(int a, int b, int ch);
short memo_dp[MAX][MAX][MAX/2];
short memo_helper[MAX][MAX/2][MAX][MAX/2];
int memo_slovo[MAX][MAX][26];

inline int next( int i ) { return i+1 < n ? i+1 : 0; }
inline int prev( int i ) { return i-1 >= 0 ? i-1 : n-1; }

inline int size( int i, int j ) {
    if( j >= i ) return j-i+1;
    else return j+n-i+1;
}

int mix(int a, int b, int c) {
    int &result = memo_mix[a][b][c];
    if( result != -1 ) return result;

    result = !(a+b+c);
    if( a ) result += mix( a-1, b, c );
    if( b ) result += mix( a, b-1, c );
    if( c ) result += mix( a, b, c-1 );
    result %= MOD;

    return result;
}

int rec( int lo, int mid, int hi ) {
    int sz = size(lo, hi);
    if( sz == 1 ) return 1;

    short &result = memo_dp[lo][mid][hi/2];
    if( result >= 0 ) return result;
    result = 0;

    for( int x = lo; x != mid; x = next(x) ) {
        int sz_x = size(lo, x);
        if( sz_x % 2 == 0 ) continue;
        for( int y = hi; y != mid; y = prev(y) ) {
            int sz_y = size(y, hi);
            if( sz_y % 2 == 0 ) continue;

            int v = mix((sz-sz_x-sz_y)/2, sz_x/2, sz_y/2);
            v = v * rec(next(x), mid, prev(y)) % MOD;
            v = v * helper(lo, x, y, hi) % MOD;
            result = (result + v) % MOD;
        }
    }

    return result;
}

int helper(int a, int b, int c, int d) {
    short &result = memo_helper[a][b/2][c][d/2];
    if( result >= 0 ) return result;
    result = 0;

    for( int ch = 0; ch < 26; ++ch )
        result = (result + slovo(a, b, ch) * slovo(c, d, ch)) % MOD;

    return result;
}

int slovo(int a, int b, int ch) {
    int &result = memo_slovo[a][b][ch];
    if( result >= 0 ) return result;
    result = 0;

    int c = next(b);
    for( int e = a; e != c; e = next(e) )
        if( tip[e] == ch+'A' )
            result = (result + rec(a, e, b)) % MOD;

    return result;
}

int main( void ) {
    scanf( "%d", &k );
    n = 2*k+1;
    scanf( "%s", tip );
    memset( memo_dp, -1, sizeof memo_dp );
    memset( memo_mix, -1, sizeof memo_mix );
    memset( memo_helper, -1, sizeof memo_helper );
    memset( memo_slovo, -1, sizeof memo_slovo );

    int result = 0;
  /*
    if( n % 2 == 0 ) {
        for( int a = 0; a < n; ++a )
            for( int c = 0; c < n; ++c ) {
                if( a%2 == c%2 ) continue;
                int b = prev(c), d = prev(a);
                for( int e = a; e != c; e = next(e) )
                    for( int f = c; f != a; f = next(f) ) {
                        if( e > f ) continue;

                        int v = rec(a, e, b) * rec(c, f, d) % MOD;
                        v = v * mix(0, size(a, b)/2, size(c, d)/2) % MOD;
                        result = (result + v) % MOD;
                    }
            }
    } else {
*/
        for( int i = 0; i < n; ++i )
            for( int j = 0; j < n; ++j )
                result = (result + rec( i, j, prev(i) )) % MOD;
    //}
    printf( "%d\n", result );

    return 0;
}
