#include<bits/stdc++.h>
#define eps 1e-10
#define Pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
#define endl '\n'
using namespace std;
///ComputationalGeometry_2D:
///{
struct point
{
long double x,y;
point(long double x = 0,long double y = 0):x(x),y(y) {}
};
typedef point Vector;
struct Line
{
point A,B;
Line(point a = point(0,0),point b = point(0,0)):A(a),B(b) {}
};
struct Segment
{
point A,B;
Segment(point a = point(0,0),point b = point(0,0)):A(a),B(b) {}
};
Vector operator + (Vector a, Vector b) { return Vector(a.x+b.x,a.y+b.y); }
Vector operator - (Vector a, Vector b) { return Vector(a.x-b.x,a.y-b.y); }
Vector operator * (long double a, Vector b) { return Vector(a*b.x,a*b.y); }
Vector operator / (Vector a, long double b) { return Vector(a.x/b,a.y/b); }
long double Dot(Vector a, Vector b) { return (a.x*b.x+a.y*b.y); }
long double Cross(Vector a, Vector b) { return (a.x*b.y-a.y*b.x); }
bool Left_of_Line(point a,Line b)
{
if ((b.A.y-b.B.y) > eps) swap(b.A,b.B);
point P = b.A;
Vector V1 = a-P, V2 = b.B-P;
if (Cross(V1,V2) < -eps) return true;
else return false;
}
bool Right_of_Line(point a,Line b)
{
if ((b.A.y-b.B.y) > eps) swap(b.A,b.B);
point P = b.A;
Vector V1 = a-P, V2 = b.B-P;
if (Cross(V1,V2) > eps) return true;
else return false;
}
bool On_the_Line(point a,Line b)
{
if (b.A.y-b.B.y > eps) swap(b.A,b.B);
point P = b.A;
Vector V1 = a-P, V2 = b.B-P;
if (Cross(V1,V2) < eps && Cross(V1,V2) > -eps) return true;
else return false;
}
long double angle(Line a)
{
if ((a.A.x-a.B.x) < eps && (a.A.x-a.B.x) > -eps) return Pi/2;
return (long double)atanl((a.A.y-a.B.y)/(a.A.x-a.B.x));
}
long double angle(point a) { return atan2l(a.y,a.x); }
point intersection(Line a,Line b)
{
long double lambda = Cross(a.B-a.A,b.A-a.A)/Cross(a.B-a.A,b.B-a.A);
return (-(1/(lambda-1)))*(b.A-b.B)+b.B;
}
pair<bool,point> intersection(Segment a,Segment b)
{
long double lambda = Cross(a.B-a.A,b.A-a.A)/Cross(a.B-a.A,b.B-a.A);
long double k = (-(1/(lambda-1)));
long double p = Cross(b.B-b.A,a.A-b.A)*Cross(b.B-b.A,a.B-b.A);
if (-eps < k && k < 1+eps && p < -eps) return make_pair(true,k*(b.A-b.B)+b.B);
else return make_pair(false,point(0,0));
}
///}
long long Read(){
long long f = 1, x = 0; char c = getchar();
while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); }
while (isdigit(c)) { x = x*10+c-'0'; c = getchar(); }
return x*f;
}
struct node
{
long double x;
long long y;
} a[10000010] ;
long long T,n,tot;
long long ans = 0;
bool Cmp(node a,node b)
{
return a.x-b.x < -eps || (a.x-b.x > -eps && a.x-b.x < eps && a.y > b.y);
}
void Make(point x,point y)
{
a[++tot].x = angle(x); a[tot].y = +1;
a[++tot].x = angle(y); a[tot].y = -1;
}
int main()
{
T = Read();
for (int t=1; t<=T; t++)
{
{
n = Read(); tot = 0;
for (int i=1; i<=n; i++)
{
long long x1 = Read(), y1 = Read(), x2 = Read(), y2 = Read();
point X = point(x1,y1), Y = point(x2,y2);
if (angle(X)-angle(Y) > eps) swap(X,Y);
Segment seg = Segment(X,Y);
Segment x_axis1 = Segment(point(0,0),point(1e7,0));
pair<bool,point> k = intersection(x_axis1,seg);
if (k.first)
{
a[++tot].x = -Pi; a[tot].y = +1;
a[++tot].x = angle(X); a[tot].y = -1;
a[++tot].x = angle(Y); a[tot].y = +1;
a[++tot].x = Pi; a[tot].y = -1;
}
else Make(X,Y);
}
}
{
ans = 0;
sort(a+1,a+tot+1,Cmp);
long long cnt = 0, A = 0, B = 0; a[0].x = 1000;
for (int i=1; i<=tot; i++)
{
if (!(a[i].x-a[i-1].x < eps && a[i].x-a[i-1].x > -eps))
{
ans = max(ans,cnt+A);
cnt = cnt+A-B;
A = 0, B = 0;
}
if (a[i].y == 1) A++; else B++;
}
ans = max(ans,cnt+A);
cnt = cnt+A-B;
}
cout << ans << endl;
}
return 0;
}