#include <bits/stdc++.h>
using namespace std;
int n=0,l=1,r,lefts,rights;
int b[1000009];
struct node
{
int where;
char what;
};
stack <node> s;
int main()
{
string c;
cin>>c;
n=c.length();
int is=0;
while(is<n)
{
if(c[is]==')')
{
if(!s.empty())
{
if(s.top().what=='(')
{
node no=s.top();
s.pop();
b[no.where]=no.where,b[is+1]=no.where;
}
}
}
else if(c[is]=='(') s.push({is+1,'('});
is++;
}
for(int i=1;i<=n;i++){
cout<<b[i]<<" ";
}
cout<<endl;
b[n+1]=0;
int T;
cin>>T;
while(T--)
{
int book[100009];
for(int i=1;i<=n;i++) book[i]=0;
int l,r,ans=0;cin>>l>>r;
for(int i=l;i<=r;i++)
{
if(b[i]>0)
{
if(book[b[i]]>0)
{
book[b[i]]--;
ans+=2;
}
else
book[b[i]]++;
}
}
cout<<ans<<endl;
}
return 0;
}