#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int add(int a, int b) {
return (a + b) % MOD;
}
int solve_subtask_2(string S, int N, int M, int K) {
int totalWays = 0;
int questionMarks = count(S.begin(), S.end(), '?');
for (int mask = 0; mask < (1 << questionMarks); ++mask) {
string temp = S;
int idx = 0;
for (int i = 0; i < N; ++i) {
if (temp[i] == '?') {
temp[i] = (mask & (1 << idx)) ? 'A' : 'B';
idx++;
}
}
int immunity = 0;
for (int i = M; i <= N; ++i) {
bool same = true;
for (int j = 0; j < M - 1; ++j) {
if (temp[i - j - 1] != temp[i - j - 2]) {
same = false;
break;
}
}
if (same) immunity++;
}
if (immunity == K) totalWays = add(totalWays, 1);
}
return totalWays;
}
int solve_subtask_4(string S, int N) {
string pattern1 = string("ABABABABABABABAB").substr(0, N);
string pattern2 = string("BABABABABABABABA").substr(0, N);
auto matchesPattern = [&](string &pattern) {
for (int i = 0; i < N; ++i) {
if (S[i] != '?' && S[i] != pattern[i]) return false;
}
return true;
};
int count = 0;
if (matchesPattern(pattern1)) count = add(count, 1);
if (matchesPattern(pattern2)) count = add(count, 1);
return count;
}
int solve_subtask_5(string S, int N, int M) {
vector<vector<int>> dp(N + 1, vector<int>(2, 0));
dp[0][0] = dp[0][1] = 1;
for (int i = 1; i <= N; ++i) {
for (int c = 0; c <= 1; ++c) {
dp[i][c] = 0;
for (int j = max(0, i - M); j < i; ++j) {
bool valid = true;
for (int k = j; k < i; ++k) {
if (S[k] != '?' && S[k] != (c ? 'B' : 'A')) {
valid = false;
break;
}
}
if (valid) dp[i][c] = add(dp[i][c], dp[j][c ^ 1]);
}
}
}
return add(dp[N][0], dp[N][1]);
}
int main() {
int N, M, K;
cin >> N >> M >> K;
string S;
cin >> S;
if (N <= 20) {
cout << solve_subtask_2(S, N, M, K) << endl;
} else if (M == 2 && K == 0) {
cout << solve_subtask_4(S, N) << endl;
} else if (K == 0) {
cout << solve_subtask_5(S, N, M) << endl;
} else {
cout << 0 << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTU9EID0gMTAwMDAwMDAwNzsKCmludCBhZGQoaW50IGEsIGludCBiKSB7CiAgICByZXR1cm4gKGEgKyBiKSAlIE1PRDsKfQoKaW50IHNvbHZlX3N1YnRhc2tfMihzdHJpbmcgUywgaW50IE4sIGludCBNLCBpbnQgSykgewogICAgaW50IHRvdGFsV2F5cyA9IDA7CiAgICBpbnQgcXVlc3Rpb25NYXJrcyA9IGNvdW50KFMuYmVnaW4oKSwgUy5lbmQoKSwgJz8nKTsKICAgIAogICAgZm9yIChpbnQgbWFzayA9IDA7IG1hc2sgPCAoMSA8PCBxdWVzdGlvbk1hcmtzKTsgKyttYXNrKSB7CiAgICAgICAgc3RyaW5nIHRlbXAgPSBTOwogICAgICAgIGludCBpZHggPSAwOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTjsgKytpKSB7CiAgICAgICAgICAgIGlmICh0ZW1wW2ldID09ICc/JykgewogICAgICAgICAgICAgICAgdGVtcFtpXSA9IChtYXNrICYgKDEgPDwgaWR4KSkgPyAnQScgOiAnQic7CiAgICAgICAgICAgICAgICBpZHgrKzsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgaW50IGltbXVuaXR5ID0gMDsKICAgICAgICBmb3IgKGludCBpID0gTTsgaSA8PSBOOyArK2kpIHsKICAgICAgICAgICAgYm9vbCBzYW1lID0gdHJ1ZTsKICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBNIC0gMTsgKytqKSB7CiAgICAgICAgICAgICAgICBpZiAodGVtcFtpIC0gaiAtIDFdICE9IHRlbXBbaSAtIGogLSAyXSkgewogICAgICAgICAgICAgICAgICAgIHNhbWUgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2FtZ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ICAgICAgICAgIGRwW2ldW2NdID0gMDsKICAgICAgICAgICAgZm9yIChpbnQgaiA9IG1heCgwLCBpIC0gTSk7IGogPCBpOyArK2opIHsKICAgICAgICAgICAgICAgIGJvb2wgdmFsaWQgPSB0cnVlOwogICAgICAgICAgICAgICAgZm9yIChpbnQgayA9IGo7IGsgPCBpOyArK2spIHsKICAgICAgICAgICAgICAgICAgICBpZiAoU1trXSAhPSAnPycgJiYgU1trXSAhPSAoYyA/ICdCJyA6ICdBJykpIHsKICAgICAgICAgICAgICAgICAgICAgICAgdmFsaWQgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHZhbGlkKSBkcFtpXVtjXSA9IGFkZChkcFtpXVtjXSwgZHBbal1bYyBeIDFdKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gYWRkKGRwW05dWzBdLCBkcFtOXVsxXSk7Cn0KCmludCBtYWluKCkgewogICAgaW50IE4sIE0sIEs7CiAgICBjaW4gPj4gTiA+PiBNID4+IEs7CiAgICBzdHJpbmcgUzsKICAgIGNpbiA+PiBTOwoKICAgIGlmIChOIDw9IDIwKSB7CiAgICAgICAgY291dCA8PCBzb2x2ZV9zdWJ0YXNrXzIoUywgTiwgTSwgSykgPDwgZW5kbDsKICAgIH0gZWxzZSBpZiAoTSA9PSAyICYmIEsgPT0gMCkgewogICAgICAgIGNvdXQgPDwgc29sdmVfc3VidGFza180KFMsIE4pIDw8IGVuZGw7CiAgICB9IGVsc2UgaWYgKEsgPT0gMCkgewogICAgICAgIGNvdXQgPDwgc29sdmVfc3VidGFza181KFMsIE4sIE0pIDw8IGVuZGw7CiAgICB9IGVsc2UgewogICAgICAgIGNvdXQgPDwgMCA8PCBlbmRsOyAKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=