RT
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
inline int read(){
int res=0;
char ch=getchar();
while(ch<'0'||ch>'9')
ch=getchar();
while(ch>='0'&&ch<='9'){
res=(res<<1)+(res<<3)+(ch^'0');
ch=getchar();
}
return res;
}
int n,q,Log[maxn];
char s[maxn],c;
vector<int> G[maxn];
struct LCA {
struct Tree {
int dep, dp[20], ans[20][2];
} T[maxn];
void init(int u) {
for (int i = 0; i < G[u].size(); ++i) {
int v = G[u][i];
if (v == T[u].dp[0])
continue;
T[v].dep = T[u].dep + 1;
T[v].dp[0] = u;
T[v].ans[0][s[u]=='G']=1;
T[v].ans[0][s[v]=='G']=1;
for (int j = 1; j <= Log[T[v].dep]; ++j){
T[v].dp[j] = T[T[v].dp[j - 1]].dp[j - 1];
T[v].ans[j][0] = T[v].ans[j - 1][0] | T[T[v].dp[j - 1]].ans[j - 1][0];
T[v].ans[j][1] = T[v].ans[j - 1][1] | T[T[v].dp[j - 1]].ans[j - 1][1];
}
init(v);
}
}
inline bool get(int u, int v) {
bool p=(c=='G'),ans=0;
if (T[u].dep > T[v].dep)
swap(u, v);
while (T[v].dep != T[u].dep){
ans |= T[v].ans[Log[T[v].dep - T[u].dep]][p];
v = T[v].dp[Log[T[v].dep - T[u].dep]];
}
if (u == v)
return ans;
for (int k = Log[T[u].dep]; k >= 0; --k)
if (T[u].dp[k] != T[v].dp[k]){
ans |= T[u].ans[k][p] | T[v].ans[k][p];
u = T[u].dp[k], v = T[v].dp[k];
}
return ans | T[u].ans[0][p];
}
}y;
int main(){
n=read(),q=read();
for(int i=1;i<=n;++i)
cin>>s[i];
for(int i=1;i<n;++i){
int u=read(),v=read();
G[u].push_back(v);
G[v].push_back(u);
}
for(int i=2;i<=n;++i)
Log[i]=Log[i>>1]+1;
y.init(1);
for(int i=1;i<=q;++i){
int a=read(),b=read();
cin>>c;
putchar(y.get(a,b)?'1':'0');
}
return 0;
}