#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
    C(){}
};

namespace std{
    bool operator < (const P& a, const P& b){
        return !EQ(a.X,b.X) ? a.X<b.X : a.Y+EPS<b.Y;
    }
    bool operator == (const P& a, const P& b){
        return abs(a-b) < EPS;
    }
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}
P unit(const P &p){
    return p/abs(p);
}
P rotate(const P &p, double rad){
    return p *P(cos(rad), sin(rad));
}

bool intersectSS(const L& a, const L& b){
    return ( ccw(a[0],a[1],b[0]) *ccw(a[0],a[1],b[1]) <= 0 ) &&
        ( ccw(b[0],b[1],a[0]) *ccw(b[0],b[1],a[1]) <= 0 );
}
bool intersectSP(const L& s, const P &p){
    return abs(cross(s[0]-p, s[1]-p))<EPS  && dot(s[0]-p, s[1]-p)<EPS;
}

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]);
}
double distanceLP(const L &l, const P &p) {
    return abs(cross(l[1]-l[0], p-l[0])) /abs(l[1]-l[0]);
}

bool isParallel(const P &a, const P &b){
    return abs(cross(a,b)) < EPS;
}
bool isParallel(const L &a, const L &b){
    return isParallel(a[1]-a[0], b[1]-b[0]);
}

P crosspointLL(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]);
  return m[0] + B/A *(m[1]-m[0]);
}

VP crosspointCL(const C &c, const L &l){
    VP ret;
    P mid = projection(l, c.p);
    double d = distanceLP(l, c.p);
    if(EQ(d, c.r)){
        ret.push_back(mid);
    }else if(d < c.r){
        double len = sqrt(c.r*c.r -d*d);
        ret.push_back(mid +len*unit(l[1]-l[0]));
        ret.push_back(mid -len*unit(l[1]-l[0]));
    }
    return ret;
}
VP crosspointCS(const C &c, const L &s){
    VP ret;
    VP cp = crosspointCL(c,s);
    for(int i=0; i<(int)cp.size(); i++){
        if(intersectSP(s, cp[i])){
            ret.push_back(cp[i]);
        }
    }
    return ret;
}
VP crosspointCC(C a, C b){
    VP ret;
    if(a.r < b.r) swap(a,b);
    double dist = abs(b.p-a.p);
    P dir = a.r*unit(b.p-a.p);
    if(EQ(dist, a.r+b.r) || EQ(dist, a.r-b.r)){
        ret.push_back(a.p +dir);
    }else if(a.r-b.r < dist && dist < a.r+b.r){
        double cos = (a.r*a.r +dist*dist -b.r*b.r)/(2*a.r*dist);
        double sin = sqrt(1 -cos*cos);
        ret.push_back(a.p +dir*P(cos, sin));
        ret.push_back(a.p +dir*P(cos, -sin));
    }
    return ret;
}

bool in_sector(const P &p, const C &c, double s, double t){
    if(abs(p -c.p) > c.r +EPS) return false;
    if(abs(p -c.p) < EPS) return true;
    double angle = arg(p -c.p);
    if(angle < 0) angle += 2*PI;
    angle *= 180/PI;
    if(s<t){
        if(s < angle +EPS && angle < t +EPS){
            return true;
        }
    }else{
        if((0 < angle +EPS && angle < t +EPS) || (s < angle +EPS && angle < 360 +EPS)){
            return true;
        }
    }
    return false;
}

int main(){
    int ds;
    cin >> ds;
    for(int rep=0; rep<ds; rep++){
        int n;
        cin >> n;
        vector<C> c(n);
        vector<L> l(2*n);
        vector<double> s(n), t(n);
        for(int i=0; i<n; i++){
            double x,y,r;
            cin >> x >> y >> r >> s[i] >> t[i];
            c[i] = C(P(x, y), r);
            l[2*i +0] = L(c[i].p, c[i].p +rotate(P(r, 0), s[i]*PI/180));
            l[2*i +1] = L(c[i].p, c[i].p +rotate(P(r, 0), t[i]*PI/180));
        }

        VP cand;
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                VP cp = crosspointCC(c[i], c[j]);
                cand.insert(cand.end(), cp.begin(), cp.end());
            }
            for(int j=0; j<2*n; j++){
                VP cp = crosspointCS(c[i], l[j]);
                cand.insert(cand.end(), cp.begin(), cp.end());
            }
        }
        for(int i=0; i<2*n; i++){
            for(int j=i+1; j<2*n; j++){
                if(!isParallel(l[i], l[j]) && intersectSS(l[i], l[j])){
                    cand.push_back(crosspointLL(l[i], l[j]));
                }
            }
        }

        int ans=0;
        for(int i=0; i<(int)cand.size(); i++){
            int sub=0;
            for(int j=0; j<n; j++){
                if(in_sector(cand[i], c[j], s[j], t[j])){
                    sub++;
                }
            }
            ans = max(ans, sub);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3724