#include<bits/stdc++.h>
using namespace std;
int main()
{
int t, i, j, k, a, b, n, s;
while(cin >> t)
{
for(k=1; k<=t; k++)
{
cin >> a >> b;
s = 0;
for(j=1; j<=b; j++)
{
cin >> n;
int c[n], fact = 1;
for(i=0; i<n; i++)
{
cin >> c[i];
if(i != n -1)
fact = ((fact%a) * (c[i]%a))%a;
}
fact = (fact*c[n-1])%a;
s += fact;
}
s = s%a;
cout << s << endl;
}
}
return 0;
}
Comments
Post a Comment