#include <bits/stdc++.h>
using namespace std;
int t, n, Q[5001], QA[5001], QAQ[5001];
string s;
int main() {
cin >> t;
while (t--) {
cin >> s;
memset(Q, 0, sizeof(Q));
memset(QA, 0, sizeof(QA));
memset(QAQ, 0, sizeof(QAQ));
for (int i = 0; i < s.size(); i++) {
Q[i] = Q[i - 1], QA[i] = QA[i - 1], QAQ[i] = QAQ[i - 1];
if (s[i] == 'Q') Q[i]++, QAQ[i] += QA[i - 1], QAQ[i] %= (long long)1e9 + 7;
else QA[i] += Q[i - 1], QA[i] %= (long long)1e9 + 7;
}
cout << QAQ[s.size() - 1] << endl;
}
return 0;
}
借鉴一下代码 |