#include<stdio.h>
int main()
{
long n,friends,boxes,k,product,sum,temp;
scanf("%ld",&n);
while(n--){
scanf("%ld %ld",&friends,&boxes);
sum=0;
while(boxes--){
product=1;
scanf("%ld",&k);
while(k--){
scanf("%ld",&temp);
product=(product*temp)%friends;
}
sum=(sum+product)%friends;
}
printf("%ld\n",sum);
}
return 0;
}
int main()
{
long n,friends,boxes,k,product,sum,temp;
scanf("%ld",&n);
while(n--){
scanf("%ld %ld",&friends,&boxes);
sum=0;
while(boxes--){
product=1;
scanf("%ld",&k);
while(k--){
scanf("%ld",&temp);
product=(product*temp)%friends;
}
sum=(sum+product)%friends;
}
printf("%ld\n",sum);
}
return 0;
}
No comments:
Post a Comment