#include <bits/stdc++.h>
using namespace std;

const int MAXH = 100;
const int MAXW = 100;
const int MAXS = 1000;
const int MOD = 1000000007;

string S;
int H, W;
char M[MAXH][MAXW + 1];
int dp[MAXH][MAXW][MAXS];

int f(int i, int j, int k) {
    if (i < 0 or i >= H or j < 0 or j >= W)
        return 0;

    int &res = dp[i][j][k];

    if (res != -1)
        return res;

    res = 0;
    if (M[i][j] == S[k]) {
        if (k + 1 == S.length()) {
            res = 1;
        } else {
            for (int di=-1; di<=1; di++)
                for (int dj=-1; dj<=1; dj++)
                    if (di != 0 or dj != 0)
                        res = (res + f(i + di, j + dj, k + 1)) % MOD;
        }
    }

    return res;
}


int main() {
    cin >> S;
    cin >> H >> W;

    for (int i=0; i<H; i++) {
        cin >> M[i];
    }

    memset(dp, -1, sizeof dp);
    int answer = 0;

    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            answer = (answer + f(i, j, 0)) % MOD;
        }
    }

    cout << answer << endl;
}
