#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) const int MOD = 1e9 + 7; const string t = "PDCA"; int n, m; string s; vector edges[100000]; long long w[100000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> s; REP (i, m) { int u, v; cin >> u >> v; --u, --v; edges[u].push_back(v); edges[v].push_back(u); } queue q; REP (i, n) if (s[i] == 'P') { q.push(i); w[i] = 1; } long long ret = 0; while (!q.empty()) { int v = q.front(); q.pop(); if (s[v] == 'A') { ret += w[v]; ret %= MOD; } else { char nxt = t[t.find(s[v]) + 1]; for (int u: edges[v]) { if (s[u] == nxt) { if (!w[u]) q.push(u); w[u] += w[v]; } } } } cout << ret << endl; return 0; }