#include using namespace std; int64_t solve(string &s, string &t, vector> &edges, vector &dp, int now, int64_t mod) { if (0 <= dp[now]) { return dp[now]; } size_t x = t.find(s[now]) + 1; int64_t r = 0; for (int next : edges[now]) { if (t.find(s[next]) == x) { (r += solve(s, t, edges, dp, next, mod)) %= mod; } } return dp[now] = r; } int main() { int64_t n, m, mod = 1000000007; string s, t = "PDCA"; cin >> n >> m >> s; vector> edges(n); for (int i = 0; i < m; i++) { int p, q; cin >> p >> q; p--; q--; edges[p].emplace_back(q); edges[q].emplace_back(p); } vector dp(n, -1); for (int i = 0; i < n; i++) { if (s[i] == 'A') { dp[i] = 1; } } int64_t ans = 0; for (int i = 0; i < n; i++) { if (s[i] == 'P') { (ans += solve(s, t, edges, dp, i, mod)) %= mod; } } cout << ans << endl; return 0; }