#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef long double R;
typedef complex<R> P;

const R EPS = 1e-10;
const R PI = acos((R)(-1));

R cross(P a, P b) { return a.real() * b.imag() - a.imag()*b.real(); }
R dot(P a, P b) { return a.real()*b.real()+a.imag()*b.imag(); }
int sgn(R a) {
    if (a < -EPS) return -1;
    if (a > EPS) return 1;
    return 0;
}

int sgn(R a, R b) {
    return sgn(b-a);
}

bool near(P a, P b) {
    return !sgn(abs(a-b));
}
int ccw(P a, P b, P c) {
    if (near(a, c) || near(b, c)) return 0;
    int s = sgn(cross(b-a, c-a));
    if (s) return s;
    if (dot(b-a, c-a) < 0) return 2;
    if (dot(a-b, c-b) < 0) return -2;
    return 0;
}

R sacos(R d) {
    d = max<R>(-1, d);
    d = min<R>(1, d);
    return acos(d);
}
struct L {
    P x, y;
    L() {}
    L(P x, P y) : x(x), y(y) {}
};

P vec(const L &l) {
    return l.y - l.x;
}

R abs(const L &l) {
    return abs(vec(l));
}

R arg(const L &l) {
    return arg(vec(l));
}

R deg2rad(R x) {
    return x/180*PI;
}

R radNorP(R x) {
    return fmod(fmod(x, 2*PI) + 2*PI, 2*PI);
}

bool inR(R l, R r, R x) {
    l = radNorP(l);
    r = radNorP(r);
    x = radNorP(x);
    if (!sgn(l, x) || !sgn(r, x)) return 2;
    if (!sgn(l, r)) return 0;
    if (sgn(l, r) == 1) {
        if (sgn(l, x) == 1 && sgn(x, r) == 1) return 1;
    } else {
        if (sgn(x, r) == 1 || sgn(l, x) == 1) return 1;
    }
    return 0;
}

R distLP(const L &l, const P &p) {
    return abs(cross(vec(l), p-l.x)/abs(l));
}

struct C {
    P p;
    R r;
    C() {}
    C(P p, R r) : p(p), r(r) {}
};

int crossLC(const L &l, const C &c, L &r) {
    R u = distLP(l, c.p);
    int si = sgn(u - c.r);
    if (si == 1) return 0;
    P v = (l.y-l.x) / abs(l) * P(0, -1);
    v *= u;
    if (ccw(l.x, l.y, c.p) < 0) v *= -1;
    if (si == 0) {
        r.x = r.y = c.p + v;
        return 1;
    }
    r.x = c.p + v + polar<R>(sqrt(c.r*c.r - u*u), arg(l));
    r.y = c.p + v - polar<R>(sqrt(c.r*c.r - u*u), arg(l));
    return 2;
}

int crossLL(const L &l, const L &m, P &r) {
    L mm = L(m.x - l.x, m.y - l.x);
    mm.x *= polar<R>(1, -arg(l));
    mm.y *= polar<R>(1, -arg(l));
    if (sgn(vec(mm).imag()) == 0) {
        r = l.x;
        if (sgn(mm.x.imag()) == 0) return -1;
        return 0;
    }
    r = mm.x - vec(mm) * (mm.x.imag() / vec(mm).imag());
    r *= polar<R>(1, arg(l));
    r += l.x;
    return 1;
}

int crossCC(const C &c, const C &d, R &l, R &r) {
    if (near(c.p, d.p) && !sgn(c.r, d.r)) {
        l = 0; r = 2*PI;
        return -1;
    }
    R di = abs(c.p - d.p);
    if (sgn(c.r+d.r, di) == 1) return 0;
    if (sgn(di, abs(c.r-d.r)) == 1) return 0;
    R bth = arg(d.p - c.p);
    R th = sacos((c.r*c.r + di*di - d.r*d.r) / (2*c.r*di));
    l = bth - th;
    r = bth + th;
    if (sgn(th) == 0) return 1;
    return 2;
}

struct Sec {
    C c;
    R l, r;
    Sec() {}
    Sec(C c, R l, R r) : c(c), l(l), r(r) {}
};

bool crossSecP(const Sec &s, const P &p) {
    P pp = p - s.c.p;
    if (sgn(s.c.r, abs(pp)) == 1) return false;
    if (sgn(abs(pp)) == 0) return true;
    return inR(s.l, s.r, arg(pp)) > 0;
}

const int MN = 20;

void solve() {
    int n;
    cin >> n;
    Sec s[MN];
    vector<L> vl;
    vector<C> vc;
    for (int i = 0; i < n; i++) {
        R x, y, r, al, ar;
        cin >> x >> y >> r >> al >> ar;
        s[i] = Sec(C(P(x, y), r), deg2rad(al), deg2rad(ar));
        vl.push_back(L(s[i].c.p, s[i].c.p + polar(s[i].c.r, s[i].l)));
        vl.push_back(L(s[i].c.p, s[i].c.p + polar(s[i].c.r, s[i].r)));
        vc.push_back(s[i].c);
    }

    vector<P> vp;
    int u = (int)vl.size();
    for (int i = 0; i < u; i++) {
        for (int j = i+1; j < u; j++) {
            P p;
            if (crossLL(vl[i], vl[j], p) == 1) {
                vp.push_back(p);
            }
        }
    }

    int w = (int)vc.size();
    for (int i = 0; i < w; i++) {
        for (int j = i+1; j < w; j++) {
            R l, r;
            if (crossCC(vc[i], vc[j], l, r)) {
                vp.push_back(vc[i].p + polar(vc[i].r, l));
                vp.push_back(vc[i].p + polar(vc[i].r, r));
            }
        }
    }

    for (int i = 0; i < u; i++) {
        for (int j = 0; j < w; j++) {
            L l;
            if (crossLC(vl[i], vc[j], l)) {
                vp.push_back(l.x);
                vp.push_back(l.y);
            }
        }
    }
    int res = 0;
    for (P p: vp) {
        int sm = 0;
        for (int i = 0; i < n; i++) {
            if (crossSecP(s[i], p)) sm++;
        }
        res = max(res, sm);
    }
    cout << res << endl;
}

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1324