#include #include #include using namespace std; using ll = long long; const ll MOD = 1e9 + 7; const string PDCA = "PDCA"; int main() { int N, M; cin >> N >> M; string S; cin >> S; vector path[N]; for (int i = 0; i < M; ++i) { int u, v; cin >> u >> v; --u, --v; path[u].push_back(v); path[v].push_back(u); } ll dp[4][N]; fill(dp[0], dp[4], 0); for (int v = 0; v < N; ++v) { if (S[v] == PDCA[0]) dp[0][v] = 1; } for (int k = 1; k < 4; ++k) { for (int v = 0; v < N; ++v) { if (S[v] != PDCA[k]) continue; for (int sv : path[v]) { dp[k][v] += dp[k - 1][sv]; } dp[k][v] %= MOD; } } ll ans = 0; for (int v = 0; v < N; ++v) { ans += dp[3][v]; } cout << ans % MOD << endl; return 0; }