#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF (1<<29) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() #define uniq(v) v.erase(unique(all(v)),v.end()) #define MOD 1000000007 string s; int n, m; vector edge[100000]; int dp[100000]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; cin >> s; rep(i,m) { int u, v; cin >> u >> v; u--; v--; if (s[u] == 'P' && s[v] == 'D' || s[u] == 'D' && s[v] == 'C' || s[u] == 'C' && s[v] == 'A') { edge[u].push_back(v); } if (s[v] == 'P' && s[u] == 'D' || s[v] == 'D' && s[u] == 'C' || s[v] == 'C' && s[u] == 'A') { edge[v].push_back(u); } } rep(i, n)if (s[i] == 'P')dp[i] = 1; rep(c,3) { rep(i, n)if("PDCA"[c] ==s[i] && dp[i]){ for (int u : edge[i]) { dp[u] += dp[i]; dp[u] %= MOD; } } } int ans = 0; rep(i,n)if(s[i]=='A') { ans += dp[i]; ans %= MOD; } cout << ans << endl; return 0; }