this should be easy

[c]

#include<stdio.h>

int main() {

int i,j,k,h,y,p,hr[3650],ans,n,c;

while(scanf("%d" ,&c)==1) {

n=0;

do{

ans=0;

if(n>=c) break;

for(i=0;i<3650;i++) hr

*=0;*

scanf("%d", &h);

if(h<7||h>3650)break;

scanf("%d", &p);

if(p<1||p>100)break;

for(j=0;j<p;j++) {

k=y=0;

scanf("%d", &y);

if(y%7==0&&y>7) break;

while(1) {

k+=y;

if(k>h) break;

if( ((k==6 || k==7) && k<=7) || ( (k%7==6 || k%7==0) && k>7 )) {continue; }

else hr[k]=1;

}

}

if(y%7==0&&y>7) break;

for(i=0;i<3650;i++) if(hr

scanf("%d", &h);

if(h<7||h>3650)break;

scanf("%d", &p);

if(p<1||p>100)break;

for(j=0;j<p;j++) {

k=y=0;

scanf("%d", &y);

if(y%7==0&&y>7) break;

while(1) {

k+=y;

if(k>h) break;

if( ((k==6 || k==7) && k<=7) || ( (k%7==6 || k%7==0) && k>7 )) {continue; }

else hr[k]=1;

}

}

if(y%7==0&&y>7) break;

for(i=0;i<3650;i++) if(hr

*==1 ) ans++;*

printf("%d\n",ans);

n++;

}while(1);

}

return 1;

}

[/c]printf("%d\n",ans);

n++;

}while(1);

}

return 1;

}

[/c]