#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    // if (abs(a-b)<EPS) return 0;
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L() {}
};
typedef vector<P> G;
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
  C() {}
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSS2(const L &s, const L &t) { // 接しているやつは交差と考えない
  REP(i, 2) {
    if (ccw(s[0], s[1], t[i]) == 0) {
      int c = ccw(s[0],s[1],t[!i]);
      if (s[0] == t[i]) {
        if (c!=-2&&c) return 0;
      } else if (s[1] == t[i]) {
        if (c!=2&&c) return 0;
      } else if (abs(c)==1) return 0;
    }
  }
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
P reflection(const L &l, const P &p) {
  return p + P(2,0) * (projection(l, p) - p);
}
double distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double istanceLS(const L &l, const L &s) {
  if (intersectLS(l, s)) return 0;
  return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
vector<P> crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  vector<P> res;
  if (abs(A) < EPS && abs(B) < EPS) {
    res.push_back(m[0]);
    return res;
  }
  if (abs(A) < EPS) return res;
  res.push_back(m[0] + B / A * (m[1] - m[0]));
  return res;
}

vector<P> crosspointLC(const L &l, const C &c) {
  vector<P> ret;
  P center = projection(l, c.p);
  double d = abs(center - c.p);
  double t = sqrt(c.r * c.r - d * d);
  if (isnan(t)) { return ret; }
  P vect = (l[1] - l[0]);
  vect /= abs(vect);
  ret.push_back(center - vect * t);
  if (t > EPS) {
    ret.push_back(center + vect * t);
  }
  return ret;
}

vector<P> crosspointSC(const L &s, const C &c) {
  vector<P> ret;
  vector<P> nret = crosspointLC(s, c);
  FOR(it, nret)
    if (intersectSP(s, *it))
      ret.push_back(*it);
   return ret;
}

vector<P> crosspointCC(const C &c1, const C &c2) {
  vector<P> ret;
  double d = abs(c1.p - c2.p);
  if (max(c1.r, c2.r) - min(c1.r, c2.r) - d> -EPS) { return ret; }
  double x = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d);
  P start = c1.p + (c2.p - c1.p) / d * x;
  P vect = (c1.p - c2.p) * P(0.0, 1.0);
  return crosspointLC(L(start, start + vect), c1);
}
int m;

P p[20];
double r[20], s[20], t[20];
C c[20];
L l[20][2];

int check(const P &q) {
  int res = 0;
  REP(i,m) {
    if (abs(q-p[i]) <= EPS) {
      res++;
      continue;
    }
    if (abs(q-p[i]) <= r[i]+EPS) {
      double ang = arg(q-p[i])*180/PI;
      if (ang < 0) ang += 360;
      // cout << s[i] << " " << t[i] << " " << q-p[i] << " " << ang << endl;
      if (s[i] < t[i]) {
        if (s[i] <= ang && ang <= t[i]) {
          res++;
        }
      } else {
        if (ang <= t[i] || s[i] <= ang) {
          res++;
        }
      }
    }
  }
//  cout << q << " " << res << endl;
  return res;
}

int check(const vector<P> &v) {
  int res = 0;
  FOR(it,v) {
    chmax(res, check(*it));
  }
  return res;
}

int main() {
  int T;
  cin >> T;
  while(T--) {
    cin >> m;
    REP(i,m) {
      cin >> p[i].real() >> p[i].imag() >> r[i] >> s[i] >> t[i];
      c[i] = C(p[i], r[i]);
      l[i][0] = L(p[i], p[i]+polar(r[i], s[i]/180*PI));
      l[i][1] = L(p[i], p[i]+polar(r[i], t[i]/180*PI));
    }
    int ans = 1;
    REP(i,m) {
      chmax(ans, check(p[i]));
      REP(j,i) {
        chmax(ans, check(crosspointCC(c[i],c[j])));
        REP(k,2) {
          REP(u,2) {
            chmax(ans, check(crosspoint(l[i][k],l[j][u])));
          }
          chmax(ans, check(crosspointLC(l[i][k],c[j])));
          chmax(ans, check(crosspointLC(l[j][k],c[i])));
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1328