#include<complex>
#include<vector>
#include<iostream>
#include<stack>
#include<cmath>
#include<algorithm>
#include<iomanip>
 
enum CCW{FRONT=0x01,RIGHT=0x02,BACK=0x04,LEFT=0x08,OVER=0x10};
enum CIRCLE_RELATION{CIRCLE_SAME=0x01,CIRCLE_CONTAIN=0x02,
		     CIRCLE_NO_CROSS=0x04,CIRCLE_ONE_CROSS=0x08,
		     CIRCLE_ONE_INSIDE_CROSS=0x10,CIRCLE_TWO_CROSS=0x20};
#define sc second
#define fr first
 
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define foreach(i,o) for(__typeof((o).begin()) i = (o).begin(); i != (o).end(); ++i)
 
using namespace std;
 
typedef double elem;
typedef complex<elem> point, vec;
typedef pair<point, point> line, hline, seg, pp;
 
const elem infty = 1e40;
const elem eps = 1.0e-8;
const elem pi = acos(-1.0);
point base(0,0);
 
// oÍ
ostream &operator<<(ostream &os, const pair<point,point> &p){
  os << p.fr << "-" << p.sc;
  return os;
}
 
// lZ
inline elem sq(elem a){ return a*a; }
inline elem cq(elem a){ return a*a*a; }
 
// pxÏ·
elem rad(elem deg){ return (deg/180)*pi; }
elem deg(elem rad){ return (rad*180)/pi; }

// ®¬_Ìô¢AÈÇ
bool eq(elem a, elem b){ return abs(a-b) < eps; }
bool eqv(vec a, vec b){ return eq( abs(b-a),0); }
 
namespace std{
  bool operator<(const point &a, const point &b){
    if(!eq(a.real(),b.real()))return a.real()<b.real();
    if(!eq(a.imag(),b.imag()))return a.imag()<b.imag();
    return false;
  }
}
 
// ð_«
struct Point{
  point p;
  Point(point p):p(p){}
  Point(double x, double y):p(x,y){}
  bool operator<(const Point &t)const{
    if( !eq( p.real(), t.p.real() ) ) return p.real() < t.p.real();
    if( !eq( p.imag(), t.p.imag() ) ) return p.imag() < t.p.imag();
    return false;
  }
};

// _Iy[^
bool far(point a, point b){ return abs(b-a)>0; }
bool near(point a, point b){ return abs(b-a)<=0; }
elem dot(vec a, vec b){ return (a.real() * b.real() + a.imag() * b.imag() ); }
elem cross(vec a, vec b){ return ( a.real() * b.imag() - a.imag() * b.real() ); }
 
// CCW oXg¾ªA¸xÉæé
inline int ccw(const point &a, point b, point x){
  b -= a;
  x -= a;
  if( eq(cross(b,x),0.0) && dot(b,x) < 0 ) return BACK;
  if( eq(cross(b,x),0.0) && abs(b) < abs(x) ) return FRONT;
  if( eq(cross(b,x),0.0) ) return OVER;
  if( cross(b,x) > 0 ) return LEFT;
  if( cross(b,x) < 0 ) return RIGHT;
}
 
// a©çbÜÅvñèÌpxAàpA]ñ]
elem varg(vec a, vec b){
  elem ret=arg(a)-arg(b);
  if(ret<0)ret+=2*pi;
  if(ret>2*pi)ret-=2*pi;
  if(eq(ret,2*pi))ret=0;
  return ret;
}
elem varg2(vec a, vec b){
  elem ret = varg(a,b);
  if(ret>pi)return 2*pi-ret;
  return ret;
}
elem arg(vec a, vec b){ return acos( dot(a,b) / ( abs(a) * abs(b) ) ); }
point rot(point p, elem theta){ return p * polar((elem)1.0, theta); }
point rotdeg(point p, elem deg){ return p * polar((elem)1.0, rad(deg)); }
point proj(line l, point p){
  elem t=dot(p-l.first,l.first-l.second)/abs(l.first-l.second);
  return l.first + t*(l.first-l.second);
}
point reflect(point a, point b, point x){
  if( ccw(a,b,x) & (OVER|FRONT|BACK) ) return x;
  vec uv = (b-a)/abs(b-a);
  return -2.*( (x-a)-dot((x-a),uv)*uv )+x;
}
 
// ñ_Ô£A¼üÆ_ÌÅZ£AüªÆ_ÌÅZ£
elem dist(point a, point b){ return abs(a-b); }
elem dist_l(line l, point x){ return abs(cross(l.sc-l.fr,x-l.fr)) / abs(l.sc-l.fr); }
elem dist_seg(seg s, point x)
{
  if( dot(s.sc-s.fr,x-s.fr)<0 ) return abs(x-s.fr);
  if( dot(s.fr-s.sc,x-s.sc)<0 ) return abs(x-s.sc);
  return dist_l(s,x);
}
 
// PÊxNgA@üxNgAPÊ@üxNg
vec uvec(vec a){ return a / abs(a); }
vec nmr(vec a){ return a * vec(0,-1); }
vec nml(vec a){ return a * vec(0,1); }
vec unmr(vec a){ return uvec( nmr(a) ); }
vec unml(vec a){ return uvec( nml(a) ); }
 
// ¼ðA½s»è
bool orth(point a1, point a2, point b1, point b2){ return eq( dot( a2 - a1, b2 - b1 ), 0 ); }
bool orth(vec v1, vec v2){ return eq( dot(v1, v2), 0 ); }
bool prll(point a1, point a2, point b1, point b2){ return eq( cross( a2 - a1, b2 - b1 ), 0 ); }
bool prll(vec v1, vec v2){ return eq( cross(v1, v2), 0 ); }
 
// üªg£
line expandLine(line l, elem mag){
  line ret = l;
  vec vf(l.first - l.second);
  vec vs(l.second - l.first);
  ret.first = l.second + mag * vf;
  ret.second = l.first + mag * vs;
  return ret;
}
 
// üªÌð·»è
inline bool intersectedSS(const seg &a, const seg &b)
{
  int cwaf=ccw(a.fr,a.sc,b.fr);
  int cwbf=ccw(b.fr,b.sc,a.fr);
  int cwas=ccw(a.fr,a.sc,b.sc);
  int cwbs=ccw(b.fr,b.sc,a.sc);
  if( cwaf==OVER || cwas==OVER || cwbf==OVER || cwbs==OVER ) return true;
  return ( cwaf | cwas ) == (LEFT|RIGHT) && ( cwbf | cwbs ) == (LEFT|RIGHT);
}
 
// ¼üÌð·»è
bool intersectedLL(line a, line b){ return !eq( cross(a.sc-a.fr,b.sc-b.fr), 0.0 ); }
 
// ð_vZ
point intersectionSS(seg a, seg b)
{
  elem d1 = dist_l(b,a.fr);
  elem d2 = dist_l(b,a.sc);
  return a.fr + ( d1 / (d1 + d2 ) ) * (a.sc-a.fr);
}
point intersectionLL(line a, line b)
{
  vec va = a.sc - a.fr;
  vec vb = b.sc - b.fr;
  return a.fr + va * ( cross(vb, b.fr - a.fr) / cross(vb,va) );
}
 
// üªð_êÅ
bool intersectionLL(line a, line b, point &ret){
  return intersectedLL( a, b ) ? ret = intersectionLL( a, b ), true : false;
}
bool intersectionLH(line a, hline b, point &ret){
  point tmp;
  return intersectionLL(a,b,tmp) ? ( ccw(b.fr,b.sc,tmp)&(OVER|FRONT) ? ret=tmp, true : false ) : false;
}
bool intersectionLS(line l, seg s, point &ret){
  point tmp;
  return intersectionLL(l,s,tmp) ? ( ccw(s.fr,s.sc,tmp)&OVER ? ret=tmp, true : false ) : false;
}
bool intersectionHH(hline a, hline b, point &ret){
  point tmp;
  return intersectionLL(a,b,tmp) ? ( ccw(a.fr,a.sc,tmp)&(OVER|FRONT)&&ccw(b.fr,b.sc,tmp)&(OVER|FRONT) ? ret = tmp, true : false ) : false;
}
bool intersectionHS(hline a, seg s, point &ret){
  point tmp;
  return intersectionLS(a,s,tmp) ? ( ccw(a.fr,a.sc,tmp)&(OVER|FRONT) ? ret = tmp, true : false ) : false;
}
bool intersectionSS(seg a, seg b, point &ret){
  return intersectedSS(a,b) ? ret = intersectionSS(a,b), true : false;
}
 
elem areaOfPolygon(const vector<point> &vp){
  elem ret = 0;
  for(int i = 0; i < vp.size(); ++i){
    ret += cross(vp[i],vp[(i+1)%vp.size()]);
  }
  return abs(ret/2.0);
}
 
/* Op` */
struct triangle{
  vector<point> p;
  triangle():p(3,point(0,0)){}
  triangle(point a,point b,point c){p.push_back(a);p.push_back(b);p.push_back(c);}
  bool contains(point t)const{
    int ccw01=ccw(p[0],p[1],t),ccw02=ccw(p[1],p[2],t),ccw03=ccw(p[2],p[0],t);
    return ccw01==ccw02&&ccw02==ccw03;
  }
};
 
/* é` */
struct rectangle{
  point tl,br;
  rectangle():tl(0,0),br(0,0){}
  rectangle(point a, point b):tl(a),br(b){}
  bool contains(const point &t)const{
    return ( tl.real()<=t.real()&&t.real()<=br.real()&&
	     br.imag()<=t.imag()&&t.imag()<=tl.imag() );
  }
};
 
/* ~ */
struct circle{
  point c;
  elem r;
  circle():c(point(0,0)),r(0){}
  circle(point c, elem r):c(c),r(r){}
  bool incircle(point t){
    return abs(t-c)<=r;
  }
};

// ¶E»è(for arg sort)
bool isRight(vec base, vec isv){
  if( eq( cross(base,isv), 0 ) ) return abs(isv)<abs(base);
  return cross(base,isv)<0;
}
bool isLeft(vec base, vec isv){
  if( eq( cross(base,isv), 0 ) ) return abs(isv)<abs(base);
  return cross(base,isv)>0;
}
 
// vargÌÙ¤ª¼´I¾ªAx¢Bpxªµ¢êÍªêèÅÈ¢ÌÅÓ
bool cmpArg(const point &a, const point &b){
  return ccw(base,a,b)==RIGHT;
};
 
// ÀWärÖ@a ª b Ì¶ºÉ éÆ«Atrue(yÀWDæ)
bool cmpYx(const point &a, const point &b){
  if( eq(a.imag(),b.imag()) ) return a.real()<b.real();
  if( a.imag()<b.imag() ) return true;
  return false;
}
bool cmpXy(const point &a, const point &b){
  if( eq(a.real(),b.real() ) ) return a.imag()<b.imag();
  if( a.real()<b.real() ) return true;
  return false;
}
 
// ~Æ¼üÌð_
bool intersectionCL(circle c, line l, pp &ret){
  vec v = nml( l.second-l.first );
  point intersection;
  if( !intersectionLL(l,line(c.c,v+c.c),intersection ) ) return false;
  if( c.incircle( intersection ) ){
    elem k = sqrt( pow(c.r,(elem)2.0) - pow(dist(intersection,c.c),(elem)2.0) );
    ret.first = k*unmr(v) + intersection;
    ret.second = k*unml(v) + intersection;
    return true;
  }
  return false;
}
 
// ~ÆüªÌð_
int intersectionCS(circle c, seg l, pp &ret){
  int num = 0;
  pp ret_cand;
  if( intersectionCL( c, l, ret_cand ) ){
    if( ccw( l.fr, l.sc, ret_cand.fr ) & OVER ){ ret.first = ret_cand.first; ++num; }
    if( ccw( l.fr, l.sc, ret_cand.sc ) & OVER ){ num == 0 ? ret.first = ret_cand.second : ret.second = ret_cand.second; ++num; }
  }
  return num;
}
 
// 2~ÌÊuÖW
int circlesRel(circle c1, circle c2){
  elem d=abs(c1.c-c2.c);
  elem r1=c1.r;
  elem r2=c2.r;
  if(r1<r2)swap(r1,r2);
  if(eq(d,r1+r2))return CIRCLE_ONE_CROSS;
  if(eq(d,r1-r2))return CIRCLE_ONE_INSIDE_CROSS;
  if(d>r1+r2)return CIRCLE_NO_CROSS;
  if(d<r1-r2)return CIRCLE_CONTAIN;
  if(d<r1+r2)return CIRCLE_TWO_CROSS;
  if(near(c1.c,c2.c)&&eq(c1.r,c2.r))return CIRCLE_SAME;
}
 
// CÓÌñÂÌ~Ìð_
int intersectionCC(circle c1, circle c2, pp &p)
{
  if( !( circlesRel( c1, c2 ) & (CIRCLE_ONE_INSIDE_CROSS | CIRCLE_ONE_CROSS | CIRCLE_TWO_CROSS) ) ) return 0;
 
  elem d = abs(c1.c-c2.c);
  vec ab = c2.c - c1.c;
  elem k = ( sq( c1.r ) - sq( c2.r ) + sq( d ) ) / ( 2 * sq( d ) );
  point t = k * ab + c1.c;
  elem x = sqrt( sq(c1.r) - sq( d * k ) );
 
  if( eq( x, 0 ) ){
    p.first = t; return 1;
  }else{
    p.first = x * unml(ab) + t;
    p.second = x * unmr(ab) + t;
    return 2;
  }
}

struct Arc{
  elem ps,pt;
  point c,s,t;
  elem r;

  // pt

  bool inside( const point &p )const{
    if( near(p,c) ) return true;
    elem tp = varg(t-c,p-c);
    elem ps = varg(p-c,s-c);
    
    //cout << sp << ' ' << pt << ' ' << ' ' << sp + pt << ' ' << 2*pi - varg(s-c,t-c) << endl;
    //cout << abs(p-c) << ' ' << r << endl;
    if( eq( tp + ps, varg(t-c,s-c)) && abs(p-c) <= r+eps ) return true;
    return false;
  }
  
  bool is_ll(const Arc &arc, vector<point> &ret)const{
    line l1(c,s);
    line l2(c,t);

    line l3(arc.c,arc.s);
    line l4(arc.c,arc.t);

    point is;
    if( intersectionSS( l1,l3,is ) && inside(is) && arc.inside(is) ) ret.push_back( is );
    if( intersectionSS( l1,l4,is ) && inside(is) && arc.inside(is) ) ret.push_back( is );
    if( intersectionSS( l2,l3,is ) && inside(is) && arc.inside(is) ) ret.push_back( is );
    if( intersectionSS( l2,l4,is ) && inside(is) && arc.inside(is) ) ret.push_back( is );
    
    return ret.size() > 0;
  }

  void is_cl_check(int num, const Arc &arc, const pp &t, vector<point> &ret)const{
    if( num >= 1 ){
      if( inside(t.first) && arc.inside(t.first) ) ret.push_back(t.first);
    }else if( num >= 2 ){
      if( inside(t.second) && arc.inside(t.second) ) ret.push_back(t.second);
    }
  }

  bool is_cl(const Arc &arc, vector<point> &ret)const{
    circle c1(c,r);
    circle c2(arc.c,arc.r);
    
    line l1(c,s);
    line l2(c,t);
    
    line l3(arc.c,arc.s);
    line l4(arc.c,arc.t);
    
    pp p;
    
    int num = intersectionCS(c1,l3,p);
    is_cl_check(num,arc,p,ret);
    num = intersectionCS(c1,l4,p);
    is_cl_check(num,arc,p,ret);
    num = intersectionCS(c2,l1,p);
    is_cl_check(num,arc,p,ret);
    num = intersectionCS(c2,l2,p);
    is_cl_check(num,arc,p,ret);
    
    return ret.size() > 0;
  }

  bool is_cc(const Arc &arc, vector<point> &ret)const{
    circle c1(c,r);
    circle c2(arc.c,arc.r);

    pp p;
    int num = intersectionCC(c1,c2,p);
    if(num>=1){
      if( inside(p.first) && arc.inside(p.first)) ret.push_back( p.first );
    }else if(num>=2){
      if(inside(p.second) && arc.inside(p.second)) ret.push_back( p.second );
    }

    return ret.size()>0;
  }

  bool intersection( const Arc &arc, vector<point> &ret )const{
    if( inside(arc.c) ) ret.push_back( arc.c );
    if( inside(arc.s) ) ret.push_back( arc.s );
    if( inside(arc.t) ) ret.push_back( arc.t );
    
    is_ll(arc,ret);
    is_cl(arc,ret);
    is_cc(arc,ret);
  }
  
};

int main()
{
  int T;
  cin >> T;
  for(int tc=1;tc<=T;++tc){
    int m;
    int ret = 1;
    cin >> m;
    
    vector<Arc> varc;
    vector<point> check;
    for(int i = 0; i < m; ++i){

      elem x,y,r,ps,pt;
      cin >> x >> y >> r >> ps >> pt;

      Arc arc;
      arc.ps = ps;
      arc.pt = pt;
      arc.c = point(x,y);
      arc.r = r;
      arc.s = arc.c + rotdeg(point(r,0),ps);
      arc.t = arc.c + rotdeg(point(r,0),pt);
      varc.push_back( arc );
    }

    for(int i = 0; i < (int)varc.size(); ++i){
      for(int j = 0; j < (int)varc.size(); ++j){
	if( i != j )
	  varc[i].intersection( varc[j], check );
      }
    }
    
    for(int i = 0; i < (int)check.size(); ++i){
      int num = 0;
      for(int j = 0; j < (int)varc.size(); ++j){
	if( varc[j].inside( check[i] ) ) ++num;
      }
      ret = max( ret, num );
    }
    
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 0