#include<bits/stdc++.h>
using namespace std;
int main()
{
int t; cin>>t;
while(t--)
{
int n; cin>>n;
string s; cin>>s;
vector<int>leaf;
int mp[n+1];
memset(mp,0,sizeof(mp));
vector<int>par(n+2);
par[1]=-1;
for(int i=0;i<n;i++){
int x,y; cin>>x>>y;
if(x==0 && y==0){
leaf.push_back(i+1);
}else{
mp[x]=0;
mp[y]=1;
par[x]=i+1;
par[y]=i+1;
}
}
int cnt=0;
int ans=INT_MAX;
int itr=0;
for(auto x: leaf){
int u=x;
cnt=0;
while(u!=-1 ){
int left=0, right=0;
if(mp[u]==0)left=1;
else right=1;
u=par[u];
if(left && s[u-1]!='L')cnt++;
else if(right && s[u-1]!='R')cnt++;
else if(s[u-1]=='U')cnt++;
if(cnt-1>=ans)break;
}
ans=min(ans, cnt-1);
}
cout<<ans<<endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgppbnQgbWFpbigpCnsKICAgIGludCB0OyBjaW4+PnQ7CiAgICB3aGlsZSh0LS0pCiAgICB7CiAgICAgICAgaW50IG47IGNpbj4+bjsKICAgICAgICBzdHJpbmcgczsgY2luPj5zOwogICAgICAgIHZlY3RvcjxpbnQ+bGVhZjsKICAgICAgICBpbnQgbXBbbisxXTsKICAgICAgICBtZW1zZXQobXAsMCxzaXplb2YobXApKTsKICAgICAgICB2ZWN0b3I8aW50PnBhcihuKzIpOwogICAgICAgIHBhclsxXT0tMTsKICAgICAgICBmb3IoaW50IGk9MDtpPG47aSsrKXsKICAgICAgICAgICAgaW50IHgseTsgY2luPj54Pj55OwogICAgICAgICAgICBpZih4PT0wICYmIHk9PTApewogICAgICAgICAgICAgICAgbGVhZi5wdXNoX2JhY2soaSsxKTsKICAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgICBtcFt4XT0wOwogICAgICAgICAgICAgICAgbXBbeV09MTsKICAgICAgICAgICAgICAgIHBhclt4XT1pKzE7CiAgICAgICAgICAgICAgICBwYXJbeV09aSsxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGludCBjbnQ9MDsKICAgICAgICBpbnQgYW5zPUlOVF9NQVg7CiAgICAgICAgaW50IGl0cj0wOwogICAgICAgIGZvcihhdXRvIHg6IGxlYWYpewoKICAgICAgICAgICAgICAgIGludCB1PXg7CiAgICAgICAgICAgICAgICBjbnQ9MDsKICAgICAgICAgICAgICAgIHdoaWxlKHUhPS0xICl7CgogICAgICAgICAgICAgICAgICAgIGludCBsZWZ0PTAsIHJpZ2h0PTA7CiAgICAgICAgICAgICAgICAgICAgaWYobXBbdV09PTApbGVmdD0xOwogICAgICAgICAgICAgICAgICAgIGVsc2UgcmlnaHQ9MTsKICAgICAgICAgICAgICAgICAgICB1PXBhclt1XTsKICAgICAgICAgICAgICAgICAgICBpZihsZWZ0ICYmIHNbdS0xXSE9J0wnKWNudCsrOwogICAgICAgICAgICAgICAgICAgZWxzZSBpZihyaWdodCAmJiBzW3UtMV0hPSdSJyljbnQrKzsKICAgICAgICAgICAgICAgICAgICBlbHNlIGlmKHNbdS0xXT09J1UnKWNudCsrOwogICAgICAgICAgICAgICAgICAgaWYoY250LTE+PWFucylicmVhazsKICAgICAgICAgICAgICAgICAKCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIGFucz1taW4oYW5zLCBjbnQtMSk7CgogICAgICAgIH0KICAgICAKICAgIGNvdXQ8PGFuczw8ZW5kbDsKCiAgICB9Cn0=