#include <bits/stdc++.h>
using namespace std;
#define MxN 100010
#define p 1000000007
int n, a[MxN], hd[MxN], res = 0, tot = 0, N[MxN], I[MxN], sN = 0, sI = 0, f[MxN];
struct node {
int y, to;
node(int y = 0, int to = 0) : y(y), to(to) {}
}e[MxN * 2];
void add(int x, int y) {
e[++ tot] = node(y, hd[x]), hd[x] = tot;
}
void dfs(int x, int fa) {
f[x] = fa;
if (a[x] == 1) N[x] = 1;
else if (a[x]) I[x] = 1;
for (int i = hd[x]; i; i = e[i].to) {
int y = e[i].y;
if (y == fa) continue;
dfs(y, x);
N[x] += N[y], I[x] += I[y];
}
}
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i ++) {
char c; cin >> c;
if (c == 'O') a[i] = 0;
if (c == 'N') a[i] = 1, sN ++;
if (c == 'I') a[i] = 2, sI ++;
}
for (int i = 1, x, y; i < n; i ++) {
cin >> x >> y, add(x, y), add(y, x);
}
dfs(1, 0);
for (int i = 1; i <= n; i ++) {
if (a[i]) continue;
int tN = 0, tI = 0;
for (int j = hd[i]; j; j = e[j].to) {
int y = e[j].y;
if (y == f[i]) continue;
(res += N[y] * tI) %= p, tI += I[y];
(res += I[y] * tN) %= p, tN += N[y];
}
(res += (sN - tN) * tI) %= p;
(res += (sI - tI) * tN) %= p;
}
cout << res << endl;
return 0;
}