#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int N(1e4+5), M(1100000);
int a[4*N], b[4*N];
inline int id(int x){
return x+M;
}
vector<int> c;
int x[N], y[N], z[N], d[N];
int main(){
int T, n, m;
int cs=0;
for(scanf("%d", &T); T--; ){
scanf("%d", &n);
printf("Case #%d:\n", ++cs);
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
c.clear();
for(int i=0; i<n; i++){
scanf("%d%d%d%d", x+i, y+i, z+i, d+i);
int R=x[i]+z[i], L=y[i]-z[i];
if(L>R) continue;
c.push_back(R), c.push_back(L);
}
sort(c.begin(), c.end());
int e=unique(c.begin(), c.end())-c.begin();
for(int i=0; i<n; i++){
int R=x[i]+z[i], L=y[i]-z[i];
if(L>R) continue;
int id1=lower_bound(c.begin(), c.begin()+e, L)-c.begin();
int id2=upper_bound(c.begin(), c.begin()+e, R)-c.begin();
if(d[i]==-1){
a[id1]++;
a[id2]--;
}
else{
b[id1]++;
b[id2]--;
}
}
int ans=0;
for(int i=1; i<e; i++)
a[i]+=a[i-1], b[i]+=b[i-1];
for(int i=1; i<e; i++){
b[i]=max(b[i], b[i-1]);
}
for(int i=0; i<e; i++)
ans=max(ans, a[i]+b[i]);
cout<<ans<<endl;
}
return 0;
}