#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll m=100005;
ll n,t,l[m],r[m],o[m];
string s;
set<ll>d;
set<pair<ll,ll>>q;
vector<ll>a;
vector<pair<ll,ll>>v;
bool f(ll p)
{
auto it=d.lower_bound(p);
if(it==d.end())
{
return 0;
}
d.erase(it);
return 1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>t;
for(ll i=0;i<t;i++)
{
d.clear();
q.clear();
a.clear();
v.clear();
bool b=0;
cin>>n>>s;
s="."+s;
for(ll j=1;j<=n;j++)
{
cin>>l[j]>>r[j];
if(s[l[j]]=='('&&s[r[j]]=='(')
{
a.push_back(l[j]);
o[j]=0;
}
else if(s[l[j]]==')'&&s[r[j]]==')')
{
d.insert(r[j]);
o[j]=1;
}
else if(s[l[j]]=='('&&s[r[j]]==')')
{
d.insert(r[j]);
v.push_back({l[j],j});
o[j]=1;
}
else
{
d.insert(l[j]);
v.push_back({l[j],j});
o[j]=0;
}
}
for(auto p:a)
{
if(!f(p))
{
cout<<-1<<endl;
b=1;
break;
}
}
if(b)
{
continue;
}
sort(v.begin(),v.end());
ll k=-1;
while(!d.empty())
{
ll x=*d.begin();
while(k+1<(ll)v.size()&&v[k+1].first<=x)
{
k++;
ll y=v[k].second;
q.insert({r[y],y});
}
bool z=1;
if(q.empty())
{
z=0;
}
else
{
ll y=q.begin()->second;
q.erase(q.begin());
o[y]=!o[y];
if(!f(l[y]))
{
z=0;
}
if(!f(r[y]))
{
z=0;
}
}
if(!z)
{
cout<<-1<<endl;
b=1;
break;
}
}
if(b)
{
continue;
}
for(ll j=1;j<=n;j++)
{
cout<<o[j]<<" ";
}
cout<<endl;
}
return 0;
}