//2350677 2010-11-16 17:00:04 Accepted 2544 C++ 0 180 VRS
//水题
//#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#define R 40000/3.1415926/2
double CalcuLen(double x1,double y1,double z1,double x2,double y2,double z2)
{
double res;
res=sqrt(pow(x1-x2,2)+pow(y1-y2,2)+pow(z1-z2,2));
return res;
}
double CalcuMaxLen(double x,double y,double z)
{
double dis2,res;
dis2=pow(x,2)+pow(y,2)+pow(z,2);
res=sqrt(dis2-pow(R,2));
return res;
}
int main()
{
int k,m;
int i,j,count;
double satellite[105][3],target[105][3],maxLen[105];
while( scanf("%d %d",&k, &m)!=EOF && !(k==0 && m==0))
{
count=0;
for(i=0;i<k;i++)
{
scanf("%lf %lf %lf",&satellite[i][0],&satellite[i][1],&satellite[i][2]);
maxLen[i]=CalcuMaxLen(satellite[i][0],satellite[i][1],satellite[i][2]);
}
for(i=0;i<m;i++)
scanf("%lf %lf %lf",&target[i][0],&target[i][1],&target[i][2]);
for(i=0;i<m;i++)
{
for(j=0;j<k;j++)
if(maxLen[j]>CalcuLen(satellite[j][0],satellite[j][1],satellite[j][2],target[i][0],target[i][1],target[i][2]))
{
count++;
break;
}
}
printf("%d\n",count);
}
}