#include <iostream>
#include <vector>
using namespace std;
int Search(vector<vector<pair<int, int>>>& Data, pair<int, int> InputData, int Frame){
int count = 0;
bool flag = false;
if(Frame >= Data.size())
return count;
for(int i = 0; i < Data[Frame].size(); i++){
if(InputData.first == Data[Frame][i].first && InputData.second == Data[Frame][i].second)
{count ++;
Data[Frame][i].first = -1;
flag = true;
break;
}
}
if(flag)
count += Search(Data, InputData, Frame+1);
return count;
};
int main(){
int N;
cin >> N;
for(int i = 0; i < N; i++){
vector<vector<pair<int, int>>> InputData;
int M;
cin >> M;
for(int j = 0; j < M; j++){
int TmpM;
cin >> TmpM;
vector<pair<int, int>> tmp_data;
for(int k = 0; k < TmpM; k++){
int TmpX, TmpY;
cin >> TmpX >> TmpY;
tmp_data.push_back(pair<int, int>(TmpX, TmpY));
}
InputData.push_back(tmp_data);
}
int Max = 0;
for(int j = 0; j < InputData.size(); j++)
for(int k = 0; k < InputData[j].size(); k++){
if(InputData[j][k].first == -1)
continue;
int TmpOut = Search(InputData, InputData[j][k], j);
Max = TmpOut > Max ? TmpOut : Max;
}
cout << Max << endl;
}
return 0;
}