#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=100000+10;
string a;
int num[maxn],n,m;
struct node
{
int s;
int e;
int value;
}nodes[4*maxn];
int min(int a,int b)
{
if(a<b) return a;
else return b;
}
int init(int s,int e,int index)
{
nodes[index].s=s;
nodes[index].e=e;
if(s==e)
{
nodes[index].value=num[s];
return num[s];
}
int m=(s+e)/2;
nodes[index].value=min(init(s,m,2*index),init(m+1,e,2*index+1));
return nodes[index].value;
}
int query(int s,int e,int index)
{
int m=(nodes[index].s+nodes[index].e)/2;
if(s==nodes[index].s&&e==nodes[index].e) return nodes[index].value;
else if(nodes[index].s<=s&&e<=m) return query(s,e,2*index);
else if(s>=m+1&&e<=nodes[index].e) return query(s,e,2*index+1);
else return min(query(s,m,2*index),query(m+1,e,2*index+1));
}
int main()
{
//freopen("input.txt","r",stdin);
int T;
scanf("%d",&T);
for(int t=1;t<=T;t++)
{
memset(num,0,sizeof(num));
scanf("%d%d",&n,&m);
printf("Case #%d:\n",t);
cin>>a;
int temp=0;
for(int i=0;i<a.size();i++)
{
if(a[i]=='(') temp++;
else temp--;
num[i]=temp;
}
//buildtree(0,n-1,1);
init(0,n-1,1);
for(int i=1;i<=m;i++)
{
int p1,p2;
scanf("%d%d",&p1,&p2);
if(p1>p2)
<pre class="cpp" name="code">#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef unsigned long long ull;
ull min(ull a,ull b)
{
if(a<b) return a;
else return b;
}
int main()
{
//freopen("input.txt","r",stdin);
ull a,b;
while(scanf("%lld%lld",&a,&b)!=EOF)
{
double temp=a/19.0;
//cout<<temp<<endl;
ull e=a/9;
//if(s==0) s++;
ull s=ceil(temp);
int counter=0;
e=min(e,b-a);
for(int i=s;i<=e;i++)
{
if((i+a)%5==0) counter++;
}
printf("%d\n",counter);
}
}
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=2000+10;
const int inf=1<<30;
int map[maxn][maxn],f[maxn][maxn],n,m;
int min(int a,int b)
{
if(a<b) return a;
else return b;
}
int dp(int i,int j)
{
if(f[i][j]!=-1) return f[i][j];
else //return f[i][j]=min(dp(i-1,j),dp(i,j-1))+map[i][j];
{
if(i-1<=0) return f[i][j]=dp(i,j-1)+map[i][j];
else if(j-1<=0) return f[i][j]=dp(i-1,j)+map[i][j];
else return f[i][j]=min(dp(i-1,j),dp(i,j-1))+map[i][j];
}
}
int main()
{
//freopen("input.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(f,-1,sizeof(f));
for(int i=0;i<maxn;i++)
{
f[0][i]=inf;
f[i][0]=inf;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&map[i][j]);
}
}
f[1][1]=map[1][1];
int ans=dp(n,m);
printf("%d\n",ans);
}
return 0;
}
{temp=p1;p1=p2;p2=temp;}p1--;p2--;if(a[p1]==a[p2]) printf("Yes\n");else if(a[p1]=='('&&a[p2]==')'){if(query(p1,p2-1,1)<2) printf("No\n");else printf("Yes\n");}else printf("Yes\n");}}return 0;}