#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
char t[10000000];
int main()
{
int n;
char s[10],*p,*q;
while(cin>>n)
{
int i;
gets(s);
for(i=0;i<n;i++)
{
if(i>0) cout<<endl;
gets(s);
int m,n;
cin>>m>>n;
gets(s);
unsigned long long int a[m+1][n+1],b[m+1][n+1],j,k;
memset(a,0,sizeof(a));
memset(b,1,sizeof(b));
a[1][1]=1;
for(j=0;j<m;j++)
{
gets(t);
for(k=0,p=strtok(t," ");p;p=strtok(NULL," "),k++)
{
if(k==0) continue;
b[j+1][atoi(p)]=0;
a[j+1][atoi(p)]=0;
}
}
for(j=1;j<=m;j++) for(k=1;k<=n;k++)
{
if(b[j][k])
{
a[j][k]+=(a[j-1][k]+a[j][k-1]);
}
}
cout<<a[m][n]<<endl;
}
}
return 0;
}
在UVA過了,但來ZJ就WA了