最大团,建立补图。
/*****************************************
Author :Crazy_AC(JamesQi)
Time :2015
File Name :
*****************************************/
// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;
#define MEM(x,y) memset(x, y,sizeof x)
#define pk push_back
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
const double eps = 1e-10;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 510;
struct people{
int high;
string sex, music, sport;
}p[N];
int g[N][N];
bool check(int i,int j) {
return abs(p[i].high-p[j].high) <= 40 && p[i].sex != p[j].sex && p[i].music == p[j].music && p[i].sport != p[j].sport;
}
int linker[N];
bool vis[N];
int n;
bool dfs(int u) {
for (int i = 1;i <= n;++i) {
if (!vis[i] && g[u][i]) {
vis[i] = true;
if (linker[i] == -1 || dfs(linker[i])) {
linker[i] = u;
return true;
}
}
}
return false;
}
int hungary() {
memset(linker, -1,sizeof linker);
int ans = 0;
for (int i = 1;i <= n;++i) {
memset(vis, false,sizeof vis);
if (dfs(i)) ans++;
}
return ans;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
for (int i = 1;i <= n;++i) {
cin >> p[i].high >> p[i].sex >> p[i].music >> p[i].sport;
}
memset(g, 0,sizeof g);
for (int i = 1;i <= n;++i) {
for (int j = i + 1;j <= n;++j) {
if (check(i, j)) g[i][j] = g[j][i] = 1;
}
}
int ans = hungary();
printf("%d\n", n - ans/2);
}
return 0;
}