#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long MOD = 1000000007; vector< vector > P; string S; vector< long long > memo; bool is_PDCA( char a, char b ) { bool ret = false; string pdca = "PDCA"; for ( int i = 0; i < 3; i++ ) { if ( pdca[i] == a && pdca[i+1] == b ) { ret = true; } } return ret; } long long dfs( int v ) { if ( memo[v] != -1 ) { return memo[v]; } if ( S[v] == 'A' ) { return 1; } long long ret = 0; for ( int i = 0; i < P[v].size(); i++ ) { ret += dfs( P[v][i] ); ret %= MOD; } memo[v] = ret; return ret; } int main() { int N,M; cin >> N >> M >> S; P.resize(N); memo.resize(N); for ( int i = 0; i < N; i++ ) { memo[i] = -1; } vector start; for ( int i = 0; i < S.length(); i++ ) { if ( S[i] == 'P' ) { start.push_back(i); } } for ( int i = 0; i < M; i++ ) { int a,b; cin >> a >> b; a--; b--; if ( is_PDCA( S[a], S[b] ) ) { P[a].push_back( b ); } if ( is_PDCA( S[b], S[a] ) ) { P[b].push_back( a ); } } long long ans = 0; for ( int i = 0; i < start.size(); i++ ) { ans += dfs( start[i] ); ans %= MOD; } cout << ans << endl; return 0; }