#include<bits/stdc++.h>
using namespace std;
namespace IO{
char ibuf[(1<<20)+1],*iS,*iT;
#if ONLINE_JUDGE
#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<20)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
#else
#define gh() getchar()
#endif
inline long long read(){
char ch=gh();
long long x=0;
bool t=0;
while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();
while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
return t?-x:x;
}
}
using IO::read;
int n;
struct M{
int ti,cou;
};
queue<M>q;
int main()
{
n=read();
for(int i=1;i<=n;i++)
{
int t,k,c,t1;
set<int>s;
t=read();
k=read();
for(int j=1;j<=k;j++)
{
c=read();
q.push({t,c});
}
t1=t-86400;
int ss=q.size();
for(int oo=1;oo<=ss;oo++)
{
int v=q.front().ti,cc=q.front().cou;
q.pop();
if(t1<v&&v<=t)
{
q.push({v,cc});
s.insert(cc);
}
}
printf("%d",s.size());
putchar('\n');
}
return 0;
}