#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

#include <complex>

typedef complex<double> Point;

struct Line : public vector<Point> {
  Line() {;}
  Line(Point a, Point b) { push_back(a); push_back(b); }
};

struct Circle {
  Point p;
  double r;
  Circle() {;}
  Circle(Point p, double r) : p(p), r(r) {;}
};

namespace std {
  bool operator<(const Point &lhs, const Point &rhs) {
    return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
  }
}

inline double cross(const Point &a, const Point &b) {
  return imag(conj(a) * b);
}

inline double dot(const Point &a, const Point &b) {
  return real(conj(a) * b);
}

inline int ccw(Point a, Point b, Point c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0) { return 1; }
  if (cross(b, c) < 0) { return -1; }
  if (dot(b, c) < 0) { return 2; }
  if (norm(b) < norm(c)) { return -2; }
  return 0;
}




Point projection(const Line &l, const Point &p) {
  double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
  return l[0] + t * (l[0] - l[1]);
}

Point reflection(const Line &l, const Point &p) {
  return p + 2.0 * (projection(l, p) - p);
}

double distanceLP(const Line &l, const Point &p) {
  return abs(p - projection(l, p));
}


bool intersectLL(const Line &l, const Line &m) {
  return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS ||
         abs(cross(l[1] - l[0], m[0] - l[0])) < EPS;
}

bool intersectLS(const Line &l, const Line &s) {
  return cross(l[1] - l[0], s[0] - l[0]) *
         cross(l[1] - l[0], s[1] - l[0]) < EPS;
}

bool intersectLP(const Line &l, const Point &p) {
  return abs(cross(l[1] - p, l[0] - p)) < EPS;
}

bool intersectSS(const Line &s, const Line &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 intersectSP(const Line &s, const Point &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < EPS;
}


Point crosspointSS(const Line &l, const Line &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) {
    //assert(false);
    if (intersectSP(l, m[0])) { return m[0]; }
    if (intersectSP(l, m[1])) { return m[1]; }
    if (intersectSP(m, l[0])) { return l[0]; }
    if (intersectSP(m, l[1])) { return l[1]; }
    return m[0];
  }
  if (abs(A) < EPS) { assert(false); }
  return m[0] + B / A * (m[1] - m[0]);
}

vector<Point> crosspointLC(const Line &l, const Circle &c) {
  vector<Point> ret;
  Point 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; }
  Point 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;
}


// no checked
vector<Point> crosspointCC(const Circle &c1, const Circle &c2) {
  vector<Point> 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);
  Point start = c1.p + (c2.p - c1.p) / d * x;
  Point vect = (c1.p - c2.p) * Point(0.0, 1.0);
  return crosspointLC(Line(start, start + vect), c1);
}

vector<Point> points;
double r[100];
double start[100];
double end[100];
int n;

int Count(Point p) {
  int ret = 0;
  REP(i, n) {
    if (abs(p - points[i]) < EPS) { ret++; continue; }
    if (abs(p - points[i]) - r[i] > EPS) { continue; }
    vector<pair<double, int> > rads;
    rads.push_back(make_pair(start[i], 1));
    rads.push_back(make_pair(start[i] + 2 * PI, 1));
    rads.push_back(make_pair(end[i], -1));
    rads.push_back(make_pair(end[i] + 2 * PI, -1));
    rads.push_back(make_pair(arg(p - points[i]) - EPS, 2));
    rads.push_back(make_pair(arg(p - points[i]) + EPS, -2));
    rads.push_back(make_pair(arg(p - points[i]) + 2 * PI - EPS, 2));
    rads.push_back(make_pair(arg(p - points[i]) + 2 * PI + EPS, -2));
    sort(rads.begin(), rads.end());
    int ok = 0;
    FORIT(it, rads) {
      int s = it->second > 0 ? 1 : 0;
      int index = abs(it->second) - 1;
      if (s) {
        ok |= 1 << index;
      } else {
        ok &= ~(1 << index);
      }
      if (ok == 3) { ret++; break; }
    }
  }
  return ret;
}

int main() {
  int test;
  scanf("%d", &test);
  while (test--) {
    points.clear();
    scanf("%d", &n);
    REP(i, n) {
      double x, y;
      scanf("%lf %lf %lf %lf %lf", &x, &y, &r[i], &start[i], &end[i]);
      points.push_back(Point(x, y));
      if (start[i] > 180) { start[i] -= 360; }
      if (end[i] > 180) { end[i] -= 360; }
      start[i] *= PI / 180.0;
      end[i] *= PI / 180.0;
    }
    int ans = 0;
    REP(i, n) {
      ans = max(ans, Count(points[i]));
      REP(j, n) {
        vector<Point> ps = crosspointCC(Circle(points[i], r[i]), Circle(points[j], r[j]));
        FORIT(it, ps) { ans = max(ans, Count(*it)); }
        Line l1(points[i], points[i] + Point(cos(start[i]), sin(start[i])) * r[i]);
        Line l2(points[i], points[i] + Point(cos(end[i]), sin(end[i])) * r[i]);
        Line l3(points[j], points[j] + Point(cos(start[j]), sin(start[j])) * r[j]);
        Line l4(points[j], points[j] + Point(cos(end[j]), sin(end[j])) * r[j]);
        Line ls[4] = { l1, l2, l3, l4 };
        REP(k, 4) REP(l, k) {
          if (intersectSS(ls[k], ls[l])) {
            ans = max(ans, Count(crosspointSS(ls[k], ls[l])));
          }
          ps = crosspointLC(ls[k], Circle(points[i], r[i]));
          FORIT(it, ps) { ans = max(ans, Count(*it)); }
        }
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 0