#include<iostream>
#include<vector>
using namespace std;
int t;
int n;
int m;
bool puedeCambiar(vector<int> p)
{
for (int i = 0;i < p.size();i++)
{
if (p[i] > 1)return 1;
}
return 0;
}
bool puedenCambiar(vector<vector<int> > jugadores)
{
for (int i = 0;i < n;i++)
{
for (int j = 0;j < jugadores[i].size();j++)
{
if (jugadores[i][j] > 1)return 1;
}
return 0;
}
}
int contar(vector<int> p)
{
int s = 0;
for (int i = 0;i < p.size();i++)
{
if (p[i] >0)return s++;
}
return s;
}
int main()
{
cin >> t;
while (t--)
{
cin >> n;
cin >> m;
vector<vector<int> > jugadores;
for (int i = 0;i < n;i++)
{
jugadores.push_back(vector<int>(0));
vector<int>stickers(26, 0);
int cantidad;
cin >> cantidad;
for (int j = 0;j < cantidad;j++)
{
int sticker;
cin >> sticker;
stickers[sticker]++;
}
jugadores[i] = stickers;
}
while (puedeCambiar(jugadores[0]) && puedenCambiar(jugadores)) {
for (int j = 0;j < jugadores[0].size();j++)
{
for (int h = 1;h < n;h++)
{
for (int k = 0;k < jugadores[h].size();k++)
{
if (jugadores[0][j] > 1 && jugadores[h][j] == 0 && jugadores[h][k] > 1 && jugadores[0][k] == 0)
{
jugadores[0][j]--;
jugadores[h][j]++;
jugadores[0][k]++;
jugadores[h][k]--;
}
}
}
cout << endl;
}
}
cout << contar(jugadores[0]) << endl;
/* for (int i = 0;i < n;i++)
{
for (int j = 0;j<jugadores[i].size();j++)
{
cout << jugadores[i][j] << " ";
}
cout << endl;
}*/
}
return 0;
}