1 #include <bits/stdc++.h>
2 using namespace std;
3 const int maxn = 1000;
4 struct GUEST {
5 int s,t,x[2],y[2];
6 bool operator<(const GUEST &t) const {
7 return s < t.s;
8 }
9 } guest[maxn];
10 vector<int>g[maxn];
11 int Link[maxn];
12 bool used[maxn];
13 bool match(int u){
14 for(int i = g[u].size()-1; i >= 0; --i){
15 if(!used[g[u][i]]){
16 used[g[u][i]] = true;
17 if(Link[g[u][i]] == -1 || match(Link[g[u][i]])){
18 Link[g[u][i]] = u;
19 return true;
20 }
21 }
22 }
23 return false;
24 }
25 int main() {
26 int kase,n,h,m;
27 scanf("%d",&kase);
28 while(kase--) {
29 scanf("%d",&n);
30 for(int i = 0; i < n; ++i) {
31 scanf("%d:%d %d %d %d %d",&h,&m,&guest[i].x[0],&guest[i].y[0],&guest[i].x[1],&guest[i].y[1]);
32 guest[i].s = h*60 + m;
33 guest[i].t = guest[i].s + abs(guest[i].x[0] - guest[i].x[1]) + abs(guest[i].y[0] - guest[i].y[1]);
34 }
35 sort(guest,guest+n);
36 for(int i = 0; i < maxn; ++i) g[i].clear();
37 for(int i = 0; i < n; ++i)
38 for(int j = i + 1; j < n; ++j) {
39 int d = abs(guest[i].x[1] - guest[j].x[0]) + abs(guest[i].y[1] - guest[j].y[0]);
40 if(guest[i].t + d < guest[j].s) g[i].push_back(j);
41 }
42 memset(Link,-1,sizeof Link);
43 int ret = 0;
44 for(int i = 0; i < n; ++i){
45 memset(used,false,sizeof used);
46 if(match(i)) ++ret;
47 }
48 printf("%d\n",n-ret);
49 }
50 return 0;
51 }