#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; #define MOD 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL<<60 vector> V(100001); char S[100001]; ll DCA[100001]; // DCA[i] : i番目の文字から始まるDCAの個数 i番目がD出なかったら0 ll CA[100001]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; for (int i = 1; i <= N; i++) cin >> S[i]; for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; V[a].push_back(b); V[b].push_back(a); } // CAを埋める for (int i = 1; i <= N; i++) { if (S[i] == 'C') { for (int j = 0; j < V[i].size(); j++) { if (S[V[i][j]] == 'A') CA[i]++; } } } // DCAを埋める for (int i = 1; i <= N; i++) { if (S[i] == 'D') { for (int j = 0; j < V[i].size(); j++) { DCA[i] += CA[V[i][j]]; } } //cout << DCA[i] << " "; } ll ans = 0LL; for (int i = 1; i <= N; i++) { if (S[i] == 'P') { for (int j = 0; j < V[i].size(); j++) { ans += DCA[V[i][j]]; ans %= MOD; } } } //cout << endl; cout << ans << endl; return 0; }