#include #include using namespace std; const long long MOD = 1000000007; int main(){ int N, M; cin >> N >> M; string S; cin >> S; vector> E(N); for (int i = 0; i < M; i++){ int u, v; cin >> u >> v; u--; v--; E[u].push_back(v); E[v].push_back(u); } string T = "PDCA"; vector> dp(4, vector(N, 0)); for (int i = 0; i < N; i++){ if (S[i] == T[0]){ dp[0][i] = 1; } } for (int i = 0; i < 3; i++){ for (int j = 0; j < N; j++){ if (S[j] == T[i]){ for (int k : E[j]){ if (S[k] == T[i + 1]){ dp[i + 1][k] += dp[i][j]; dp[i + 1][k] %= MOD; } } } } } long long ans = 0; for (int i = 0; i < N; i++){ ans += dp[3][i]; } cout << ans << endl; }