use std::io::{Read, stdin}; fn main() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut tok = buf.split_whitespace(); let mut get = || tok.next().unwrap(); macro_rules! get { ($t:ty) => (get().parse::<$t>().unwrap()); () => (get!(usize)); } let md = 1_000_000_007; let n = get!(); let m = get!(); let s = get().as_bytes(); let mut graph = vec![vec![]; n]; let mut count = vec![0_u64; n]; for _ in 0..m { let u = get!()-1; let v = get!()-1; let gu = s[u]; let gv = s[v]; match (gu, gv) { (b'C',b'A') => count[u] += 1, (b'A',b'C') => count[v] += 1, (b'D',b'C')|(b'P',b'D') => graph[v].push(u), (b'C',b'D')|(b'D',b'P') => graph[u].push(v), _ => {}, } } for i in 0..s.len(){ if s[i] == b'C' { for &j in graph[i].iter() { count[j] += count[i]; count[j] %= md; } } } for i in 0..s.len(){ if s[i] == b'D' { for &j in graph[i].iter() { count[j] += count[i]; count[j] %= md; } } } let mut ans = 0; for i in 0..s.len(){ if s[i] == b'P' { ans += count[i]; ans %= md; } } println!("{}", ans); }