import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum mod = 10^^9 + 7; void main() { int[char] cnv = ['P':0, 'D':1, 'C':2, 'A':3]; int n, m; scan(n, m); auto s = readln.chomp.map!(ch => cnv[ch.to!char]).array; auto adj = new int[][](n, 0); foreach (i ; 0 .. m) { int ui, vi; scan(ui, vi); ui--, vi--; if (s[ui] > s[vi]) { swap(ui, vi); } if (s[vi] - s[ui] == 1) { adj[vi] ~= ui; } } auto dp = new int[](n); dp[] = -1; int dfs(int v) { if (s[v] == 0) { return dp[v] = 1; } if (dp[v] != -1) { return dp[v]; } dp[v] = 0; foreach (u ; adj[v]) { dp[v] += dfs(u); dp[v] %= mod; } return dp[v]; } int ans; foreach (i ; 0 .. n) { if (dp[i] == -1) { dfs(i); } if (s[i] == 3) { ans += dp[i]; ans %= mod; } } writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }