#include<bits/stdc++.h>
using namespace std;
map<string,set<string> > m;
bool check(string s,string t) {
    for(int i=0;i<s.size();i++) {
        if(s[s.size()-1-i]!=t[t.size()-1-i]){
            return false;
        }
    }
    return true;
}
bool cmp(string s,string t) {
    return s.size()<t.size();
}
int main(){
    ios::sync_with_stdio(false);
    set<string> name;
    int n;cin>>n;
    for(int i=0;i<n;i++){
        string nme,s;int t;
        cin>>nme>>t;
        name.insert(nme);
        for(int j=0;j<t;j++){
            cin>>s;
            m[nme].insert(s);
        }
    }
    map<string,set<string> >::iterator it_1;
    set<string>::iterator it_2;
    vector<string> v;
    set<string> s;
    for(it_1 = m.begin();it_1 != m.end();it_1++) {
        v.clear();s.clear();
        for(it_2=it_1->second.begin();it_2 != it_1->second.end();it_2++) {
            v.push_back(*it_2);
        }
        sort(v.begin(),v.end(),cmp);
        for(int i=0;i<v.size();i++) {
            bool flag=true;
            //检查
            for(int j=i+1;j<v.size();j++) {
                if(check(v[i],v[j])){
                    flag=false;
                }
            }
            if(flag){
                s.insert(v[i]);
            }
        }
        it_1->second=s;
    }
    //print
    cout<<name.size()<<endl;
    for(it_1=m.begin();it_1!=m.end();it_1++) {
        cout<<it_1->first<<" "<< it_1->second.size();
        for(it_2=it_1->second.begin();it_2 != it_1->second.end();it_2++) {
            cout<<" "<<*it_2;
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct kk{
    string name;
    vector<string>ve;
}emmm[22];
int ok(string a,string b){
    if(a.length()==b.length()){
        if(a==b)return 3;
        else return 1;
    }
    else if(a.length()>b.length()){
        for(int i=0;i<b.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 3;
    }
    else{
        for(int i=0;i<a.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 2;
    }
}
int find(string s){
    for(int i=0;i<20;i++){
        if(emmm[i].name.empty()||emmm[i].name==s)return i;
    }
}
int main(){
    int N;scanf("%d",&N);
    while(N--){
        string t;cin>>t;
        int n=find(t);
        emmm[n].name=t;
        int nn;scanf("%d",&nn);
        while(nn--){
            string tt;cin>>tt;
            int choic=1;
            for(int i=0;i<emmm[n].ve.size();i++){
                if(ok(emmm[n].ve[i],tt)==2){choic=max(choic,ok(emmm[n].ve[i],tt));emmm[n].ve[i]=tt;break;}
                choic=max(choic,ok(emmm[n].ve[i],tt));
            }
            if(choic==1)emmm[n].ve.push_back(tt);
        }
    }
    cout<<find("woshidashazihahahahaha")<<endl;
    for(int i=find("woshidashazihahahahaha")-1;i>=0;i--){
        cout<<emmm[i].name<<" "<<emmm[i].ve.size();
        for(int j=0;j<emmm[i].ve.size();j++){
            cout<<" "<<emmm[i].ve[j];
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
struct kk{
    string name;
    vector<string>ve;
}emmm[22];
int ok(string a,string b){
    if(a.length()==b.length()){
        if(a==b)return 3;
        else return 1;
    }
    else if(a.length()>b.length()){
        for(int i=0;i<b.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 3;
    }
    else{
        for(int i=0;i<a.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 2;
    }
}
int find(string s){
    for(int i=0;i<20;i++){
        if(emmm[i].name.empty()||emmm[i].name==s)return i;
    }
}
int main(){
    int N;cin>>N;
    while(N--){
        string t;cin>>t;
        int n=find(t);
        emmm[n].name=t;
        int nn;cin>>nn;
        while(nn--){
            string tt;cin>>tt;
            int choic=1;
            for(int i=0;i<emmm[n].ve.size();i++){
                if(ok(emmm[n].ve[i],tt)==2){choic=max(choic,ok(emmm[n].ve[i],tt));emmm[n].ve[i]=tt;break;}
                choic=max(choic,ok(emmm[n].ve[i],tt));
            }
            if(choic==1)emmm[n].ve.push_back(tt);
        }
    }
    cout<<find("woshidashazihahahahaha")<<endl;
    for(int i=find("woshidashazihahahahaha")-1;i>=0;i--){
        cout<<emmm[i].name<<" "<<emmm[i].ve.size();
        for(int j=0;j<emmm[i].ve.size();j++){
            cout<<" "<<emmm[i].ve[j];
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct kk{
    string name;
    vector<string>ve;
}emmm[22];
int ok(string a,string b){
    if(a.length()==b.length()){
        if(a==b)return 3;
        else return 1;
    }
    else if(a.length()>b.length()){
        for(int i=0;i<b.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 3;
    }
    else{
        for(int i=0;i<a.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 2;
    }
}
int find(string s){
    for(int i=0;i<20;i++){
        if(emmm[i].name.empty()||emmm[i].name==s)return i;
    }
}
int main(){
    int N;cin>>N;
    while(N--){
        string t;cin>>t;
        int n=find(t);
        emmm[n].name=t;
        int nn;cin>>nn;
        while(nn--){
            string tt;cin>>tt;
            int choic=1;
            for(int i=0;i<emmm[n].ve.size();i++){
                if(ok(emmm[n].ve[i],tt)==2){choic=max(choic,ok(emmm[n].ve[i],tt));emmm[n].ve[i]=tt;break;}
                choic=max(choic,ok(emmm[n].ve[i],tt));
            }
            if(choic==1)emmm[n].ve.push_back(tt);
        }
    }
    cout<<find("woshidashazihahahahaha")<<endl;
    for(int i=find("woshidashazihahahahaha")-1;i>=0;i--){
        cout<<emmm[i].name<<" "<<emmm[i].ve.size();
        for(int j=0;j<emmm[i].ve.size();j++){
            cout<<" "<<emmm[i].ve[j];
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
struct kk{
    string name;
    vector<string>ve;
}emmm[22];
int ok(string a,string b){
    if(a.length()==b.length()){
        if(a==b)return 3;
        else return 10;
    }
    else if(a.length()>b.length()){
        for(int i=0;i<b.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 3;
    }
    else{
        for(int i=0;i<a.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 2;
    }
}
int find(string s){
    for(int i=0;i<=20;i++){
        if(emmm[i].name.empty()||emmm[i].name==s)return i;
    }
}
int main(){
    int N;scanf("%d",&N);
    while(N--){
        string t;cin>>t;
        int n=find(t);
        emmm[n].name=t;
        int nn;scanf("%d",&nn);
        while(nn--){
            string tt;cin>>tt;
            int choic=1;
            for(int i=0;i<emmm[n].ve.size();i++){
                if(ok(emmm[n].ve[i],tt)==2){choic=max(choic,ok(emmm[n].ve[i],tt));emmm[n].ve[i]=tt;break;}
                choic=max(choic,ok(emmm[n].ve[i],tt));
            }
            if(choic==1)emmm[n].ve.push_back(tt);
        }
    }
    cout<<find("woshidashazihahahahaha")<<endl;
    for(int i=find("woshidashazihahahahaha")-1;i>=0;i--){
        cout<<emmm[i].name<<" "<<emmm[i].ve.size();
        for(int j=0;j<emmm[i].ve.size();j++){
            cout<<" "<<emmm[i].ve[j];
        }
        cout<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
struct kk{
    string name;
    vector<string>ve;
}emmm[22];
int ok(string a,string b){
    if(a.length()==b.length()){
        if(a==b)return 3;
        else return 10;
    }
    else if(a.length()>b.length()){
        for(int i=0;i<b.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 3;
    }
    else{
        for(int i=0;i<a.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 2;
    }
}
int find(string s){
    for(int i=0;i<=20;i++){
        if(emmm[i].name.empty()||emmm[i].name==s)return i;
    }
}
int main(){
    int N;scanf("%d",&N);
    while(N--){
        string t;cin>>t;
        int n=find(t);
        emmm[n].name=t;
        int nn;scanf("%d",&nn);
        while(nn--){
            string tt;cin>>tt;
            int choic=1;
            for(int i=0;i<emmm[n].ve.size();i++){
                if(ok(emmm[n].ve[i],tt)==2){choic=max(choic,ok(emmm[n].ve[i],tt));emmm[n].ve[i]=tt;break;}
                choic=max(choic,ok(emmm[n].ve[i],tt));
            }
            if(choic==1)emmm[n].ve.push_back(tt);
        }
    }
    cout<<find("woshidashazihahahahaha")<<endl;
    for(int i=find("woshidashazihahahahaha")-1;i>=0;i--){
        cout<<emmm[i].name<<" "<<emmm[i].ve.size();
        for(int j=0;j<emmm[i].ve.size();j++){
            cout<<" "<<emmm[i].ve[j];
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
struct kk{
    string name;
    vector<string>ve;
}emmm[22];
int ok(string a,string b){
    if(a.length()==b.length()){
        if(a==b)return 3;
        else return 1;
    }
    else if(a.length()>b.length()){
        for(int i=0;i<b.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 3;
    }
    else{
        for(int i=0;i<a.length();i++){
            if(b[b.length()-1-i]!=a[a.length()-1-i])return 1;
        }
        return 2;
    }
}
int find(string s){
    for(int i=0;i<20;i++){
        if(emmm[i].name.empty()||emmm[i].name==s)return i;
    }
}
int main(){
    int N;cin>>N;
    while(N--){
        string t;cin>>t;
        int n=find(t);
        emmm[n].name=t;
        int nn;cin>>nn;
        while(nn--){
            string tt;cin>>tt;
            int choic=1;
            for(int i=0;i<emmm[n].ve.size();i++){
                if(ok(emmm[n].ve[i],tt)==2){emmm[n].ve[i]=tt;break;}
                choic=max(choic,ok(emmm[n].ve[i],tt));
            }
            if(choic==1)emmm[n].ve.push_back(tt);
        }
    }
    cout<<find("woshidashazihahahahaha")<<endl;
    for(int i=find("woshidashazihahahahaha")-1;i>=0;i--){
        cout<<emmm[i].name<<" "<<emmm[i].ve.size();
        for(int j=0;j<emmm[i].ve.size();j++){
            cout<<" "<<emmm[i].ve[j];
        }
        cout<<endl;
    }
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<map>

using namespace std;
typedef long long ll;
const int maxn = 1000;

int n;
map<string, int>mp;
vector< string > res[maxn];

int main()
{
	scanf("%d", &n);
	int count = 0;
	for (int i = 1; i <= n; i++)
	{
		string name; cin >> name;
		int num; cin >> num;
		if (mp[name] == 0)
		{
			mp[name] = ++count;
			res[mp[name]].push_back(name);
		}
		for (int j = 0; j < num; j++)
		{
			string s; cin >> s;
			res[mp[name]].push_back(s);
		}
	}
	for (int i = 1; i <= count; i++)
	{
		if (res[i].size())
		{
			for (int j = 1; j < res[i].size(); j++)
			{
				for (int k = 1; k < res[i].size(); k++)
				{
					if (j == k)
						continue;
					reverse(res[i][j].begin(), res[i][j].end());
					reverse(res[i][k].begin(), res[i][k].end());
					if (res[i][k].size()>res[i][j].size())
					{
						reverse(res[i][j].begin(), res[i][j].end());
						reverse(res[i][k].begin(), res[i][k].end());
						continue;
					}
					else
					{
						if (res[i][j].find(res[i][k]) == 0)
						{
							res[i][k] = "ss";
						}
					}
					reverse(res[i][j].begin(), res[i][j].end());
					reverse(res[i][k].begin(), res[i][k].end());
				}
			}
		}
	}
	cout << count << endl;
	for (int i = count; i >= 1; i--)
	{
		if (res[i].size())
		{
			vector<string>str;
			cout << res[i][0] << " ";
			for (int j = 1; j < res[i].size(); j++)
			{
				if (res[i][j] != "ss")
				{
					str.push_back(res[i][j]);
				}
			}
			cout << str.size() << " ";
			for (int j = 0; j < str.size() - 1; j++)
				cout << str[j] << " ";
			cout << str.back() << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<map>

using namespace std;
typedef long long ll;

int n;
map<string, int>mp;
vector< string > res[25];

int main()
{
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
	{
		string name; cin >> name;
		int num; cin >> num;
		if (mp[name] == 0)
		{
			mp[name] = i;
			res[mp[name]].push_back(name);
		}
		for (int j = 0; j < num; j++)
		{
			string s; cin >> s;
			res[mp[name]].push_back(s);
		}
	}
	for (int i = 0; i < 25; i++)
	{
		if (res[i].size())
		{
			for (int j = 1; j < res[i].size(); j++)
			{
				for (int k = 1; k < res[i].size(); k++)
				{
					if (j == k)
						continue;
					if (res[i][j].find(res[i][k]) != string::npos)
					{
						int index = res[i][j].find(res[i][k]);
						if (index+res[i][k].size() == res[i][j].size())
							res[i][k] = "ss";
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 25; i++)
		if (res[i].size())
			ans++;
	cout << ans << endl;
	for (int i = 0; i < 25; i++)
	{
		if (res[i].size())
		{
			vector<string>str;
			cout << res[i][0] << " ";
			for (int j = 1; j < res[i].size(); j++)
			{
				if (res[i][j] != "ss")
				{
					str.push_back(res[i][j]);
				}
			}
			cout << str.size() << " ";
			for (int j = 0; j < str.size() - 1; j++)
				cout << str[j] << " ";
			cout << str.back() << endl;
		}
	}
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<map>

using namespace std;
typedef long long ll;
const int maxn=1000;

int n;
map<string, int>mp;
vector< string > res[maxn];

int main()
{
	scanf("%d", &n);
	int count = 0;
	for (int i = 1; i <= n; i++)
	{
		string name; cin >> name;
		int num; cin >> num;
		if (mp[name] == 0)
		{
			mp[name] = ++count;
			res[mp[name]].push_back(name);
		}
		for (int j = 0; j < num; j++)
		{
			string s; cin >> s;
			res[mp[name]].push_back(s);
		}
	}
	for (int i = 1; i <= count; i++)
	{
		if (res[i].size())
		{
			for (int j = 1; j < res[i].size(); j++)
			{
				for (int k = 1; k < res[i].size(); k++)
				{
					if (j == k)
						continue;
					if (res[i][j].find(res[i][k]) != string::npos)
					{
						int index = res[i][j].find(res[i][k]);
						if (index+res[i][k].size() == res[i][j].size())
							res[i][k] = "ss";
					}
				}
			}
		}
	}
	cout << count << endl;
	for (int i = count; i >=1; i--)
	{
		if (res[i].size())
		{
			vector<string>str;
			cout << res[i][0] << " ";
			for (int j = 1; j < res[i].size(); j++)
			{
				if (res[i][j] != "ss")
				{
					str.push_back(res[i][j]);
				}
			}
			cout << str.size() << " ";
			for (int j = 0; j < str.size() - 1; j++)
				cout << str[j] << " ";
			cout << str.back() << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<map>

using namespace std;
typedef long long ll;
const int maxn=1000;

int n;
map<string, int>mp;
vector< string > res[maxn];

int main()
{
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
	{
		string name; cin >> name;
		int num; cin >> num;
		if (mp[name] == 0)
		{
			mp[name] = i;
			res[mp[name]].push_back(name);
		}
		for (int j = 0; j < num; j++)
		{
			string s; cin >> s;
			res[mp[name]].push_back(s);
		}
	}
	for (int i = 0; i < maxn; i++)
	{
		if (res[i].size())
		{
			for (int j = 1; j < res[i].size(); j++)
			{
				for (int k = 1; k < res[i].size(); k++)
				{
					if (j == k)
						continue;
					if (res[i][j].find(res[i][k]) != string::npos)
					{
						int index = res[i][j].find(res[i][k]);
						if (index+res[i][k].size() == res[i][j].size())
							res[i][k] = " ";
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < maxn; i++)
		if (res[i].size())
			ans++;
	cout << ans << endl;
	for (int i = 0; i < maxn; i++)
	{
		if (res[i].size())
		{
			vector<string>str;
			cout << res[i][0] << " ";
			for (int j = 1; j < res[i].size(); j++)
			{
				if (res[i][j] != " ")
				{
					str.push_back(res[i][j]);
				}
			}
			cout << str.size() << " ";
			for (int j = 0; j < str.size() - 1; j++)
				cout << str[j] << " ";
			cout << str.back() << endl;
		}
	}
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<string>
#include<cstring>
using namespace std;
stack<string>str;
class comp
{
public:
	bool operator ()(const string &s1,const string &s2)
    {
        if(s1.size()==s2.size()&&s1!=s2)
        {
            return true;
        }
        else
            return s1.size()>s2.size();
    }
};
struct data
{
	set<string,comp>num;
};
map<string,data>cp;
void kp(data node)
{
	queue<string>p;
	map<string,int>mp;
    set<string,comp>::iterator it=node.num.begin();
    for(;it!=node.num.end();it++)
    {
    	string st=*it;
    	if(mp[st]==1)  continue;
    	for(int i=0;i<st.size();i++)
    	{
    		char tc[150];
    		memcpy(tc,&st[0]+i,st.size()-i+1);
    		mp[string(tc)]=1;
		}
		p.push(st);
	}
	cout<<p.size()<<" ";
	while(!p.empty())
	{
		cout<<p.front()<<" ";
		p.pop();
	}
	return ;
}
void work()
{
	cout<<str.size()<<endl;
	while(!str.empty())
	{
		string s=str.top();str.pop();
		cout<<s<<" ";
		kp(cp[s]);
		cout<<endl;
	}
}

int main()
{

	string name;
	int n,b;	cin>>n;
	string a;
	for(int i=1;i<=n;i++)
	{
		cin>>name>>b;
		if(cp[name].num.size()==0)  str.push(name);
		 for(int j=1;j<=b;j++)
		 {
		 	cin>>a;
		 	cp[name].num.insert(a);
		 }
	}
	work();
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;
int n;
vector<string>s[55];
int to[55][510];
int tot;
int k[510],ans[510];
int find(int i,int x)
{
	if(x==to[i][x])  return x;
	return to[i][x]=find(i,to[x][i]);
}
void cop(int w,int x,int y)
{
	int l=s[w][x].size()-1,r=s[w][y].size()-1;
	while(l>=0 && r>=0)
	{
		if(s[w][x][l]!=s[w][y][r])  return ;
		l--;r--;
	}
	if(l>=0)  to[w][y]=x;
	else  to[w][x]=y;
	return;
}
void deal(int x)
{
	for(int i=1;i<=k[x];i++)
	{
		for(int j=i+1;j<=k[x];j++)
		{
			cop(x,find(x,i),find(x,j));
		}
	}
}
int main()
{
	cin>>n;

	string a;int b;
	int now=0,tot=0;
	for(int i=1;i<=50;i++)
	{
		for(int j=1;j<=500;j++)  to[i][j]=j;
	}

	for(int i=1;i<=n;i++)
	{
		now=tot+1;
		cin>>a>>b;
		for(int j=1;j<=tot;j++)
			if(a==s[j][0])  now=j;
		if(now==tot+1)
		{
			tot++;
			s[now].push_back(a);
		}

		for(int j=1;j<=b;j++)  cin>>a,s[now].push_back(a),k[now]++;
	}
	for(int i=1;i<=tot;i++)
	{
		deal(i);
		for(int j=1;j<=k[i];j++)
		{
		//	cout<<to[i][j]<<" "<<s[i][j]<<endl;
			if(to[i][j]==j)  ans[i]++;
		}
	}
	cout<<tot<<endl;
	for(int i=1;i<=tot;i++)
	{
		cout<<s[i][0]<<" "<<ans[i]<<" ";
		for(int j=1;j<=k[i];j++)
		{
			if(to[i][j]==j)  cout<<s[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;
int n;
vector<string>s[21];
int to[21][210];
int tot;
int k[21],ans[21];
int find(int i,int x)
{
	if(x==to[i][x])  return x;
	return to[i][x]=find(i,to[x][i]);
}
void cop(int w,int x,int y)
{
	int l=s[w][x].size()-1,r=s[w][y].size()-1;
	while(l>=0 && r>=0)
	{
		if(s[w][x][l]!=s[w][y][r])  return ;
		l--;r--;
	}
	if(l>=0)  to[w][y]=x;
	else  to[w][x]=y;
	return;
}
void deal(int x)
{
	for(int i=1;i<=k[x];i++)
	{
		for(int j=i+1;j<=k[x];j++)
		{
			cop(x,find(x,i),find(x,j));
		}
	}
}
int main()
{
	cin>>n;

	string a;int b;
	int now=0,tot=0;
	for(int i=1;i<=20;i++)
	{
		for(int j=1;j<=200;j++)  to[i][j]=j;
	}

	for(int i=1;i<=n;i++)
	{
		now=tot+1;
		cin>>a>>b;
		for(int j=1;j<=tot;j++)
			if(a==s[j][0])  now=j;
		if(now==tot+1)
		{
			tot++;
			s[now].push_back(a);
		}

		for(int j=1;j<=b;j++)  cin>>a,s[now].push_back(a),k[now]++;
	}
	for(int i=1;i<=tot;i++)
	{
		deal(i);
		for(int j=1;j<=k[i];j++)
		{
		//	cout<<to[i][j]<<" "<<s[i][j]<<endl;
			if(to[i][j]==j)  ans[i]++;
		}
	}
	cout<<tot<<endl;
	for(int i=1;i<=tot;i++)
	{
		cout<<s[i][0]<<" "<<ans[i]<<" ";
		for(int j=1;j<=k[i];j++)
		{
			if(to[i][j]==j)  cout<<s[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<string>
using namespace std;
stack<string>str;
class comp
{
public:
	bool operator ()(const string &s1,const string &s2)
    {
        if(s1.size()==s2.size()&&s1!=s2)
        {
            return true;
        }
        else
            return s1.size()>s2.size();
    }
};
struct data
{
	set<string,comp>num;
};
map<string,data>cp;
void kp(data node)
{
	queue<string>p;
	map<string,int>mp;
    set<string,comp>::iterator it=node.num.begin();
    for(;it!=node.num.end();it++)
    {
    	string st=*it;
    	if(mp[st]==1)  continue;
    	for(int i=0;i<st.size();i++)
    	{
    		char tc[150];
    		memcpy(tc,&st[0]+i,st.size()-i+1);
    		mp[string(tc)]=1;
		}
		p.push(st);
	}
	cout<<p.size()<<" ";
	while(!p.empty())
	{
		cout<<p.front()<<" ";
		p.pop();
	}
	return ;
}
void work()
{
	cout<<str.size()<<endl;
	while(!str.empty())
	{
		string s=str.top();str.pop();
		cout<<s<<" ";
		kp(cp[s]);
		cout<<endl;
	}
}

int main()
{

	string name;
	int n,b;	cin>>n;
	string a;
	for(int i=1;i<=n;i++)
	{
		cin>>name>>b;
		if(cp[name].num.size()==0)  str.push(name);
		 for(int j=1;j<=b;j++)
		 {
		 	cin>>a;
		 	cp[name].num.insert(a);
		 }
	}
	work();
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

map<string,vector<string> > cnt;
map<string,vector<string> > ans;

int main(){
	int n,num;
	string name,call;
	cin>>n;
	while(n--){
		cin>>name>>num;
		while(num--){
			cin>>call;
			reverse(call.begin(),call.end());
			cnt[name].push_back(call);
		}
	}
	for(auto it:cnt){
		sort(it.second.begin(),it.second.end());
		it.second.erase(unique(it.second.begin(),it.second.end()),it.second.end());
		for(auto jt=it.second.begin();jt!=it.second.end();jt++){
			auto t=jt+1;
			if(t==it.second.end())	break;
			if(t->find(*jt)!=0)	ans[it.first].push_back(*jt);
		}
		ans[it.first].push_back(*it.second.rbegin());
	}
	cout<<ans.size()<<endl;
	for(auto it:ans){
		cout<<it.first<<" "<<it.second.size();
		for(auto jt:it.second){
			reverse(jt.begin(),jt.end());
			cout<<" "<<jt;
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

map<string,vector<string> > cnt;
map<string,vector<string> > ans;

int main(){
	int n,num;
	string name,call;
	cin>>n;
	while(n--){
		cin>>name>>num;
		while(num--){
			cin>>call;
			reverse(call.begin(),call.end());
			cnt[name].push_back(call);
		}
	}
	for(auto it:cnt){
		sort(it.second.begin(),it.second.end());
		it.second.erase(unique(it.second.begin(),it.second.end()),it.second.end());
		for(auto jt=it.second.begin();jt!=it.second.end();jt++){
			auto t=jt+1;
			if(t==it.second.end())	break;
			if(t->find(*jt)==string::npos)	ans[it.first].push_back(*jt);
		}
		ans[it.first].push_back(*it.second.rbegin());
	}
	for(auto it:ans){
		cout<<it.first<<" "<<it.second.size();
		for(auto jt:it.second){
			reverse(jt.begin(),jt.end());
			cout<<" "<<jt;
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

map<string,vector<string> > cnt;
map<string,vector<string> > ans;

int main(){
	int n,num;
	string name,call;
	cin>>n;
	while(n--){
		cin>>name>>num;
		while(num--){
			cin>>call;
			reverse(call.begin(),call.end());
			cnt[name].push_back(call);
		}
	}
	for(auto it:cnt){
		sort(it.second.begin(),it.second.end());
		it.second.erase(unique(it.second.begin(),it.second.end()),it.second.end());
		for(auto jt=it.second.begin();jt!=it.second.end();jt++){
			auto t=jt+1;
			if(t==it.second.end())	break;
			if(t->find(*jt)==0)	ans[it.first].push_back(*jt);
		}
		ans[it.first].push_back(*it.second.rbegin());
	}
	cout<<ans.size()<<endl;
	for(auto it:ans){
		cout<<it.first<<" "<<it.second.size();
		for(auto jt:it.second){
			reverse(jt.begin(),jt.end());
			cout<<" "<<jt;
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

map<string,vector<string> > cnt;
map<string,vector<string> > ans;

int main(){
	int n,num;
	string name,call;
	cin>>n;
	while(n--){
		cin>>name>>num;
		while(num--){
			cin>>call;
			reverse(call.begin(),call.end());
			cnt[name].push_back(call);
		}
	}
	for(auto it:cnt){
		sort(it.second.begin(),it.second.end());
		it.second.erase(unique(it.second.begin(),it.second.end()),it.second.end());
		for(auto jt=it.second.begin();jt!=it.second.end();jt++){
			auto t=jt+1;
			if(t==it.second.end())	break;
			if(t->find(*jt)==1)	ans[it.first].push_back(*jt);
		}
		ans[it.first].push_back(*it.second.rbegin());
	}
	cout<<ans.size()<<endl;
	for(auto it:ans){
		cout<<it.first<<" "<<it.second.size();
		for(auto jt:it.second){
			reverse(jt.begin(),jt.end());
			cout<<" "<<jt;
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

map<string,vector<string> > cnt;
map<string,vector<string> > ans;

int main(){
	int n,num;
	string name,call;
	cin>>n;
	while(n--){
		cin>>name>>num;
		while(num--){
			cin>>call;
			reverse(call.begin(),call.end());
			cnt[name].push_back(call);
		}
	}
	for(auto it:cnt){
		sort(it.second.begin(),it.second.end());
		it.second.erase(unique(it.second.begin(),it.second.end()),it.second.end());
		for(auto jt=it.second.begin();jt!=it.second.end();jt++){
			auto t=jt+1;
			if(t==it.second.end())	break;
			if(t->find(*jt)==string::npos)	ans[it.first].push_back(*jt);
		}
		ans[it.first].push_back(*it.second.rbegin());
	}
	cout<<ans.size()<<endl;
	for(auto it:ans){
		cout<<it.first<<" "<<it.second.size();
		for(auto jt:it.second){
			reverse(jt.begin(),jt.end());
			cout<<" "<<jt;
		}
		cout<<endl;
	}
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <iterator>
#include <sstream>
#include <fstream>

using namespace std;

map <string, vector <string> > mp;
map <string, int> size_map;
int main() {
  //ifstream cin("input.txt");
  string s;
  int psevd;
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> psevd;

    size_map[s] += psevd;

    for (int j = 0; j < psevd; j++) {
      string a;
      cin >> a;
      mp[s].push_back(a);
    }
  }

  map <string, vector <string> > :: iterator it = mp.begin();

  for (; it != mp.end(); ++it) {
    for (int i = 0; i < mp[it->first].size(); i++) {
      for (int j = 0; j < mp[it->first].size(); j++) {
        bool flag = false;
        if (i == j || mp[it->first][i] == "-1" || mp[it->first][j] == "-1") continue;

        if (mp[it->first][i] == mp[it->first][j]) {
          mp[it->first][i] = "-1";
          size_map[it->first]--;
          break;
        }
        if (mp[it->first][i].size() > mp[it->first][j].size()) {
          continue;
        }

        int sizer = mp[it->first][i].size();
        int dec = mp[it->first][j].size() - mp[it->first][i].size();

        for (int t = sizer - 1; t >= 0; t--) {
          if (mp[it->first][j][t + dec] != mp[it->first][i][t]) {
            //cout << t << mp[it->first][j] << " " << mp[it->first][i]<< endl;
            flag = true;
            break;
          }
        }

        if (!flag) {
          size_map[it->first]--;

          mp[it->first][i] = "-1";
          break;
        }
      }
    }
  }

  map <string, int> :: iterator itt = size_map.begin();
  int sizer = 0;
  for (; itt != size_map.end(); ++itt) {
    if (itt->second > 0) sizer++;
  }

  cout << sizer << endl;
  it = mp.begin();
  for (; it != mp.end(); ++it) {
    if (size_map[it->first] <= 0) {
      continue;
    }
    cout << it->first << " " << size_map[it->first] << " ";
    for (int i = 0; i < mp[it->first].size(); i++) {
      if (mp[it->first][i] != "-1") {
        cout << mp[it->first][i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <iterator>
#include <sstream>
//#include <fstream>

using namespace std;

map <string, vector <string> > mp;
map <string, int> size_map;
int main() {
  //ifstream cin("input.txt");
  string s;
  int psevd;
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> psevd;

    size_map[s] += psevd;

    for (int j = 0; j < psevd; j++) {
      string a;
      cin >> a;
      mp[s].push_back(a);
    }
  }

  map <string, vector <string> > :: iterator it = mp.begin();

  for (; it != mp.end(); ++it) {
    for (int i = 0; i < mp[it->first].size(); i++) {
      for (int j = 0; j < mp[it->first].size(); j++) {
        bool flag = false;
        if (i == j || mp[it->first][i] == "-1" || mp[it->first][j] == "-1") continue;

        if (mp[it->first][i] == mp[it->first][j]) {
          mp[it->first][j] = "-1";
          size_map[it->first]--;
          break;
        }
        if (mp[it->first][i].size() > mp[it->first][j].size()) {
          continue;
        }

        int sizer = mp[it->first][i].size();
        int dec = mp[it->first][j].size() - mp[it->first][i].size();

        for (int t = sizer - 1; t >= 0; t--) {
          if (mp[it->first][j][t + dec] != mp[it->first][i][t]) {
            //cout << t << mp[it->first][j] << " " << mp[it->first][i]<< endl;
            flag = true;
            break;
          }
        }

        if (!flag) {
          size_map[it->first]--;

          mp[it->first][i] = "-1";
          break;
        }
      }
    }
  }

  map <string, int> :: iterator itt = size_map.begin();
  int sizer = 0;
  for (; itt != size_map.end(); ++itt) {
    if (itt->second > 0) sizer++;
  }

  cout << sizer << endl;
  it = mp.begin();
  for (; it != mp.end(); ++it) {
    if (size_map[it->first] <= 0) {
      continue;
    }
    cout << it->first << " " << size_map[it->first] << " ";
    for (int i = 0; i < mp[it->first].size(); i++) {
      if (mp[it->first][i] != "-1") {
        cout << mp[it->first][i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <iterator>
#include <sstream>
#include <fstream>

using namespace std;

map <string, vector <string> > mp;
map <string, int> size_map;
int main() {
  ifstream cin("input.txt");
  string s;
  int psevd;
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> psevd;

    size_map[s] += psevd;

    for (int j = 0; j < psevd; j++) {
      string a;
      cin >> a;
      mp[s].push_back(a);
    }
  }

  map <string, vector <string> > :: iterator it = mp.begin();

  for (; it != mp.end(); ++it) {
    for (int i = 0; i < mp[it->first].size(); i++) {
      for (int j = 0; j < mp[it->first].size(); j++) {
        bool flag = false;
        if (i == j || mp[it->first][i] == "-1" || mp[it->first][j] == "-1") continue;

        if (mp[it->first][i] == mp[it->first][j]) {
          mp[it->first][j] = "-1";
          size_map[it->first]--;
          break;
        }
        if (mp[it->first][i].size() > mp[it->first][j].size()) {
          continue;
        }

        int sizer = mp[it->first][i].size();
        int dec = mp[it->first][j].size() - mp[it->first][i].size();

        for (int t = sizer - 1; t >= 0; t--) {
          if (mp[it->first][j][t + dec] != mp[it->first][i][t]) {
            //cout << t << mp[it->first][j] << " " << mp[it->first][i]<< endl;
            flag = true;
            break;
          }
        }

        if (!flag) {
          size_map[it->first]--;

          mp[it->first][i] = "-1";
          break;
        }
      }
    }
  }

  map <string, int> :: iterator itt = size_map.begin();
  int sizer = 0;
  for (; itt != size_map.end(); ++itt) {
    if (itt->second > 0) sizer++;
  }

  cout << sizer << endl;
  it = mp.begin();
  for (; it != mp.end(); ++it) {
    if (size_map[it->first] <= 0) {
      continue;
    }
    cout << it->first << " " << size_map[it->first] << " ";
    for (int i = 0; i < mp[it->first].size(); i++) {
      if (mp[it->first][i] != "-1") {
        cout << mp[it->first][i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <iterator>
#include <sstream>
//#include <fstream>

using namespace std;

map <string, vector <string> > mp;
map <string, int> size_map;
int main() {
  //ifstream cin("input.txt");
  string s;
  int psevd;
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> psevd;

    size_map[s] += psevd;

    for (int j = 0; j < psevd; j++) {
      string a;
      cin >> a;
      mp[s].push_back(a);
    }
  }

  map <string, vector <string> > :: iterator it = mp.begin();

  for (; it != mp.end(); ++it) {
    for (int i = 0; i < mp[it->first].size(); i++) {
      for (int j = 0; j < mp[it->first].size(); j++) {
        if (j == i && mp[it->first][j] != "-1") continue;

        stringstream s1;
        stringstream s2;

        s1 << mp[it->first][i];
        s2 << mp[it->first][j];

        int a, b;

        s1 >> a;
        s2 >> b;

        if ((b - a) % 10 == 0 && b - a >= 0) {
          mp[it->first][i] = "-1";
          size_map[it->first]--;
          break;
        }
      }
    }
  }

  map <string, int> :: iterator itt = size_map.begin();
  int sizer = 0;
  for (; itt != size_map.end(); ++itt) {
    if (itt->second > 0) sizer++;
  }

  cout << sizer << endl;
  it = mp.begin();
  for (; it != mp.end(); ++it) {
    if (size_map[it->first] <= 0) {
      continue;
    }
    cout << it->first << " " << size_map[it->first] << " ";
    for (int i = 0; i < mp[it->first].size(); i++) {
      if (mp[it->first][i] != "-1") {
        cout << mp[it->first][i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <iterator>
#include <sstream>
#include <fstream>

using namespace std;

map <string, vector <string> > mp;
map <string, int> size_map;
int main() {
  //ifstream cin("input.txt");
  string s;
  int psevd;
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> psevd;

    size_map[s] += psevd;

    for (int j = 0; j < psevd; j++) {
      string a;
      cin >> a;
      mp[s].push_back(a);
    }
  }

  map <string, vector <string> > :: iterator it = mp.begin();

  for (; it != mp.end(); ++it) {
    for (int i = 0; i < mp[it->first].size(); i++) {
      for (int j = 0; j < mp[it->first].size(); j++) {
        bool flag = false;
        if (i == j || mp[it->first][i] == "-1" || mp[it->first][j] == "-1") continue;

        if (mp[it->first][i] == mp[it->first][j]) {
          mp[it->first][j] = "-1";
          size_map[it->first]--;
          continue;
        }
        if (mp[it->first][i].size() > mp[it->first][j].size()) {
          continue;
        }

        int sizer = mp[it->first][i].size();
        int dec = mp[it->first][j].size() - mp[it->first][i].size();

        for (int t = sizer - 1; t >= 0; t--) {
          if (mp[it->first][j][t + dec] != mp[it->first][i][t]) {
            //cout << t << mp[it->first][j] << " " << mp[it->first][i]<< endl;
            flag = true;
            break;
          }
        }

        if (!flag) {
          size_map[it->first]--;

          mp[it->first][i] = "-1";
          break;
        }
      }
    }
  }

  map <string, int> :: iterator itt = size_map.begin();
  int sizer = 0;
  for (; itt != size_map.end(); ++itt) {
    if (itt->second > 0) sizer++;
  }

  cout << sizer << endl;
  it = mp.begin();
  for (; it != mp.end(); ++it) {
    if (size_map[it->first] <= 0) {
      continue;
    }
    cout << it->first << " " << size_map[it->first] << " ";
    for (int i = 0; i < mp[it->first].size(); i++) {
      if (mp[it->first][i] != "-1") {
        cout << mp[it->first][i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <iterator>
#include <sstream>
#include <fstream>

using namespace std;

map <string, vector <string> > mp;
map <string, int> size_map;
vector <string> names;
vector < vector <string> > name;

int main() {
  ifstream cin("input.txt");
  string s;
  int psevd;
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> psevd;
    names.push_back(s);
    size_map[s] += psevd;
    name.push_back(vector <string>());
    for (int j = 0; j < psevd; j++) {
      string a;
      cin >> a;
      name[i].push_back(a);
    }
  }

  for (int h = 0; h < n; h++) {
    for (int i = 0; i < name[h].size(); i++) {
      for (int j = 0; j < name[h].size(); j++) {
        if (j == i && name[h][j] != "-1") continue;
        stringstream s1;
        stringstream s2;
        s1 << name[h][i];
        s2 << name[h][j];

        int a, b;

        s1 >> a;
        s2 >> b;

        if ((b - a) % 10 == 0 && b - a >= 0) {
          name[h][i] = "-1";
          size_map[names[h]]--;
          break;
        }
      }
    }
  }

  map <string, int> :: iterator itt = size_map.begin();
  int sizer = 0;
  for (; itt != size_map.end(); ++itt) {
    if (itt->second != 0) sizer++;
  }

  cout << sizer << endl;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < name[i].size(); j++) {
      mp[names[i]].push_back(name[i][j]);
    }
  }
  map <string, vector <string> > :: iterator it = mp.begin();
  for (; it != mp.end(); ++it) {
    if (size_map[it->first] == 0) {
      continue;
    }
    cout << it->first << " " << size_map[it->first] << " ";
    for (int i = 0; i < mp[it->first].size(); i++) {
      if (mp[it->first][i] != "-1") {
        cout << mp[it->first][i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <iterator>
#include <sstream>
//#include <fstream>

using namespace std;

map <string, vector <string> > mp;
map <string, int> size_map;
int main() {
  //ifstream cin("input.txt");
  string s;
  int psevd;
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> psevd;

    size_map[s] += psevd;

    for (int j = 0; j < psevd; j++) {
      string a;
      cin >> a;
      mp[s].push_back(a);
    }
  }

  map <string, vector <string> > :: iterator it = mp.begin();

  for (; it != mp.end(); ++it) {
    for (int i = 0; i < mp[it->first].size(); i++) {
      for (int j = 0; j < mp[it->first].size(); j++) {
        if (j == i && mp[it->first][j] != "-1") continue;
        stringstream s1;
        stringstream s2;
        s1 << mp[it->first][i];
        s2 << mp[it->first][j];

        int a, b;

        s1 >> a;
        s2 >> b;

        if ((b - a) % 10 == 0 && b - a >= 0) {
          mp[it->first][i] = "-1";
          size_map[it->first]--;
          break;
        }
      }
    }
  }

  map <string, int> :: iterator itt = size_map.begin();
  int sizer = 0;
  for (; itt != size_map.end(); ++itt) {
    if (itt->second != 0) sizer++;
  }

  cout << sizer << endl;
  it = mp.begin();
  for (; it != mp.end(); ++it) {
    if (size_map[it->first] == 0) {
      continue;
    }
    cout << it->first << " " << size_map[it->first] << " ";
    for (int i = 0; i < mp[it->first].size(); i++) {
      if (mp[it->first][i] != "-1") {
        cout << mp[it->first][i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <iterator>
#include <sstream>
#include <fstream>

using namespace std;

map <string, vector <string> > mp;
map <string, int> size_map;
int main() {
  ifstream cin("input.txt");
  string s;
  int psevd;
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> psevd;

    size_map[s] += psevd;

    for (int j = 0; j < psevd; j++) {
      string a;
      cin >> a;
      mp[s].push_back(a);
    }
  }

  map <string, vector <string> > :: iterator it = mp.begin();

  for (; it != mp.end(); ++it) {
    for (int i = 0; i < mp[it->first].size(); i++) {
      for (int j = 0; j < mp[it->first].size(); j++) {
        if (j == i && mp[it->first][j] != "-1") continue;
        stringstream s1;
        stringstream s2;
        s1 << mp[it->first][i];
        s2 << mp[it->first][j];

        int a, b;

        s1 >> a;
        s2 >> b;

        if ((b - a) % 10 == 0 && b - a >= 0) {
          mp[it->first][i] = "-1";
          size_map[it->first]--;
          break;
        }
      }
    }
  }

  map <string, int> :: iterator itt = size_map.begin();
  int sizer = 0;
  for (; itt != size_map.end(); ++itt) {
    if (itt->second != 0) sizer++;
  }

  cout << sizer << endl;
  it = mp.begin();
  for (; it != mp.end(); ++it) {
    if (size_map[it->first] == 0) {
      continue;
    }
    cout << it->first << " " << size_map[it->first] << " ";
    for (int i = 0; i < mp[it->first].size(); i++) {
      if (mp[it->first][i] != "-1") {
        cout << mp[it->first][i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <iterator>
#include <sstream>
//#include <fstream>

using namespace std;

map <string, vector <string> > mp;
map <string, int> size_map;
vector <string> names;
vector < vector <string> > name;

int main() {
  //ifstream cin("input.txt");
  string s;
  int psevd;
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> psevd;
    names.push_back(s);
    size_map[s] += psevd;
    name.push_back(vector <string>());
    for (int j = 0; j < psevd; j++) {
      string a;
      cin >> a;
      name[i].push_back(a);
    }
  }

  for (int h = 0; h < n; h++) {
    for (int i = 0; i < name[h].size(); i++) {
      for (int j = 0; j < name[h].size(); j++) {
        if (j == i && name[h][j] != "-1") continue;
        stringstream s1;
        stringstream s2;
        s1 << name[h][i];
        s2 << name[h][j];

        int a, b;

        s1 >> a;
        s2 >> b;

        if ((b - a) % 10 == 0 && b - a >= 0) {
          name[h][i] = "-1";
          size_map[names[h]]--;
          break;
        }
      }
    }
  }

  map <string, int> :: iterator itt = size_map.begin();
  int sizer = 0;
  for (; itt != size_map.end(); ++itt) {
    if (itt->second != 0) sizer++;
  }

  cout << sizer << endl;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < name[i].size(); j++) {
      mp[names[i]].push_back(name[i][j]);
    }
  }
  map <string, vector <string> > :: iterator it = mp.begin();
  for (; it != mp.end(); ++it) {
    if (size_map[it->first] == 0) {
      continue;
    }
    cout << it->first << " " << size_map[it->first] << " ";
    for (int i = 0; i < mp[it->first].size(); i++) {
      if (mp[it->first][i] != "-1") {
        cout << mp[it->first][i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define vs vector<string>
#define pb push_back

bool cmp(string a, string b){
	return stoi(a) < stoi(b);
}

vector <int> strong_borders(const string& pat){
    int m = pat.size();
    vector <int> sbord(m);
    int t = -1;
    sbord[0] = 0;

    for (int j = 1; j < m; ++j){
        while( (t > -1) and pat[t+1] != pat[j]){
            t = sbord[t]-1;
        }
        if( pat[t+1] == pat[j])
            t++;

        sbord[j] = t+1;
    }
    return sbord;
}

bool KMP(const string& text, const string& pat){
    int n = text.size()-1;
    int m = pat.size()-1;
    int i = 0, j = 0, occ = 0, k = 0;

    vector<int> bords = strong_borders(pat);

    while (n - k >= m)
    {
        while (j <= m and text[i] == pat[j]){
            ++j;
            ++i;
        }

        if (j > m and k+m == n)return true;

        if(j-1 >= 0 and bords[j-1] > 0) k = i - bords[j-1];

        else{
            if(i == k) i++;
            k = i;
        }

        if(j > 0) j = bords[j-1];
    }
    return false;
}

map <string, vs > mp;

void solve(string name){
	vector<string> base = mp[name];
	sort(base.begin(), base.end(), cmp);
	//cout << "o " << name << " ta ";
	//for(auto x: base) cout << " " << x;
	//	cout << endl;
	for(int i = 0; i < base.size(); i++){
		for(int j = i+1; j < base.size(); j++){
			if(KMP(base[j],base[i]))/*cout << "deu o " << base[i] << " dentro do " << base[j] << endl, */base[i] = "", j = base.size();
		}
	}
	//cout << "base do " << name << " ficou " << endl;
	//for(auto x: base) cout << " " << x;
	//cout << endl;
	mp[name] = base;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n ; i++){
		string name;
		int qnt;
		cin >> name >> qnt;
		while(qnt--){
			string num;
			cin >> num;
			mp[name].pb(num);
		}
	}
	for(auto x : mp)solve(x.ff);
	cout << mp.size() << endl;
	for(auto x : mp){
		cout << x.ff << " ";
		int qnt = 0;
		for(auto y: x.ss) if(y != "") qnt++;
		cout << qnt;
		for(auto y: x.ss) if(y != "")cout << " " << y;

		puts("");
	}

}

// 1 2 3 4 5 6 7 8 9 10 11 12


#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define vs vector<string>
#define pb push_back

bool cmp(string a, string b){
	return stoi(a) < stoi(b);
}

vector <int> strong_borders(const string& pat){
    int m = pat.size();
    vector <int> sbord(m);
    int t = -1;
    sbord[0] = 0;

    for (int j = 1; j < m; ++j){
        while( (t > -1) and pat[t+1] != pat[j]){
            t = sbord[t]-1;
        }
        if( pat[t+1] == pat[j])
            t++;

        sbord[j] = t+1;
    }
    return sbord;
}

bool KMP(const string& text, const string& pat){
    int n = text.size()-1;
    int m = pat.size()-1;
    int i = 0, j = 0, occ = 0, k = 0;
    if(n < m) return false;

    vector<int> bords = strong_borders(pat);

    while (n - k >= m)
    {
        while (j <= m and text[i] == pat[j]){
            ++j;
            ++i;
        }

        if (j > m and k+m == n)return true;

        if(j-1 >= 0 and bords[j-1] > 0) k = i - bords[j-1];

        else{
            if(i == k) i++;
            k = i;
        }

        if(j > 0) j = bords[j-1];
    }
    return false;
}

map <string, vs > mp;

void solve(string name){
	vector<string> base = mp[name];
	sort(base.begin(), base.end(), cmp);
	//cout << "o " << name << " ta ";
	//for(auto x: base) cout << " " << x;
	//	cout << endl;
	for(int i = 0; i < base.size(); i++){
		for(int j = 0; j < base.size(); j++){
			if(i != j and KMP(base[j],base[i]))/*cout << "deu o " << base[i] << " dentro do " << base[j] << endl, */base[i] = "", j = base.size();
		}
	}
	//cout << "base do " << name << " ficou " << endl;
	//for(auto x: base) cout << " " << x;
	//cout << endl;
	mp[name] = base;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n ; i++){
		string name;
		int qnt;
		cin >> name >> qnt;
		while(qnt--){
			string num;
			cin >> num;
			mp[name].pb(num);
		}
	}
	for(auto x : mp)solve(x.ff);
	cout << mp.size() << endl;
	for(auto x : mp){
		cout << x.ff << " ";
		int qnt = 0;
		for(auto y: x.ss) if(y != "") qnt++;
		cout << qnt;
		for(auto y: x.ss) if(y != "")cout << " " << y;

		puts("");
	}

}

// 1 2 3 4 5 6 7 8 9 10 11 12


#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define vs vector<string>
#define pb push_back

vector <int> strong_borders(const string& pat){
    int m = pat.size();
    vector <int> sbord(m);
    int t = -1;
    sbord[0] = 0;

    for (int j = 1; j < m; ++j){
        while( (t > -1) and pat[t+1] != pat[j]){
            t = sbord[t]-1;
        }
        if( pat[t+1] == pat[j])
            t++;

        sbord[j] = t+1;
    }
    return sbord;
}

bool KMP(const string& text, const string& pat){
    int n = text.size()-1;
    int m = pat.size()-1;
    int i = 0, j = 0, occ = 0, k = 0;

    vector<int> bords = strong_borders(pat);

    while (n - k >= m)
    {
        while (j <= m and text[i] == pat[j]){
            ++j;
            ++i;
        }

        if (j > m and k+m == n)return true;

        if(j-1 >= 0 and bords[j-1] > 0) k = i - bords[j-1];

        else{
            if(i == k) i++;
            k = i;
        }

        if(j > 0) j = bords[j-1];
    }
    return false;
}

map <string, vs > mp;

void solve(string name){
	vector<string> base = mp[name];
	sort(base.begin(), base.end());
	//cout << "o " << name << " ta ";
	//for(auto x: base) cout << " " << x;
	//cout << endl;
	for(int i = 0; i < base.size(); i++){
		for(int j = i+1; j < base.size(); j++){
			if(KMP(base[j],base[i])) base[i] = "";
		}
	}
	//cout << "base do " << name << " ficou " << endl;
	//for(auto x: base) cout << " " << x;
	//cout << endl;
	mp[name] = base;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n ; i++){
		string name;
		int qnt;
		cin >> name >> qnt;
		while(qnt--){
			string num;
			cin >> num;
			mp[name].pb(num);
		}
	}
	for(auto x : mp) solve(x.ff);

	for(auto x : mp){
		cout << x.ff << " ";
		int qnt = 0;
		for(auto y: x.ss) if(y != "") qnt++;
		cout << qnt;
		for(auto y: x.ss) if(y != "")cout << " " << y;

		puts("");
	}

}

// 1 2 3 4 5 6 7 8 9 10 11 12


#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define vs vector<string>
#define pb push_back

bool KMP(string a, string b){
	if(a.size() > b.size()) return false;
	int n = a.size()-1;
	for(int i = b.size()-1; i >= 0; i--){
		if(n == -1) return true;
		if(b[i] != a[n--]) return false;
	}
	return true;
}

map <string, vs > mp;

void solve(string name){
	vector<string> base = mp[name];
	//cout << "o " << name << " ta ";
	//for(auto x: base) cout << " " << x;
	//	cout << endl;
	for(int i = 0; i < base.size(); i++){
		for(int j = 0; j < base.size(); j++){
			if(i != j and base[j] != "" and base[i] != "" and  KMP(base[i],base[j])){
				base[i] = "";
				break;
			}
		}
	}
	//cout << "base do " << name << " ficou " << endl;
	//for(auto x: base) cout << " " << x;
	//cout << endl;
	mp[name] = base;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n ; i++){
		string name;
		int qnt;
		cin >> name >> qnt;
		while(qnt--){
			string num;
			cin >> num;
			mp[name].pb(num);
		}
	}
	for(auto x : mp)solve(x.ff);
	cout << mp.size() << endl;
	for(auto x : mp){
		cout << x.ff << " ";
		int qnt = 0;
		for(auto y: x.ss) if(y != "") qnt++;
		cout << qnt;
		for(auto y: x.ss) if(y != "")cout << " " << y;

		puts("");
	}

}

// 1 2 3 4 5 6 7 8 9 10 11 12


#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define vs vector<int>
#define pb push_back

vector <int> strong_borders(const string& pat){
    int m = pat.size();
    vector <int> sbord(m);
    int t = -1;
    sbord[0] = 0;

    for (int j = 1; j < m; ++j){
        while( (t > -1) and pat[t+1] != pat[j]){
            t = sbord[t]-1;
        }
        if( pat[t+1] == pat[j])
            t++;

        sbord[j] = t+1;
    }
    return sbord;
}

bool KMP(const string& text, const string& pat){
    int n = text.size()-1;
    int m = pat.size()-1;
    int i = 0, j = 0, occ = 0, k = 0;

    vector<int> bords = strong_borders(pat);

    while (n - k >= m)
    {
        while (j <= m and text[i] == pat[j]){
            ++j;
            ++i;
        }

        if (j > m and k+m == n)return true;

        if(j-1 >= 0 and bords[j-1] > 0) k = i - bords[j-1];

        else{
            if(i == k) i++;
            k = i;
        }

        if(j > 0) j = bords[j-1];
    }
    return false;
}

map <string, vs > mp;

void solve(string name){
	vector<int> base = mp[name];
	sort(base.begin(), base.end());
	//cout << "o " << name << " ta ";
	//for(auto x: base) cout << " " << x;
	//cout << endl;
	for(int i = 0; i < base.size(); i++){
		for(int j = i+1; j < base.size(); j++){
			if(KMP(to_string(base[j]),to_string(base[i]))) base[i] = -1;
		}
	}
	//cout << "base do " << name << " ficou " << endl;
	//for(auto x: base) cout << " " << x;
	//cout << endl;
	mp[name] = base;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n ; i++){
		string name;
		int qnt;
		cin >> name >> qnt;
		while(qnt--){
			int num;
			cin >> num;
			mp[name].pb(num);
		}
	}
	for(auto x : mp) solve(x.ff);

	for(auto x : mp){
		cout << x.ff << " ";
		int qnt = 0;
		for(auto y: x.ss) if(y != -1) qnt++;
		cout << qnt;
		for(auto y: x.ss) if(y != -1)cout << " " << y;

		puts("");
	}

}

// 1 2 3 4 5 6 7 8 9 10 11 12


#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define vs vector<string>
#define pb push_back

bool cmp(string a, string b){
	return stoi(a) < stoi(b);
}

vector <int> strong_borders(const string& pat){
    int m = pat.size();
    vector <int> sbord(m);
    int t = -1;
    sbord[0] = 0;

    for (int j = 1; j < m; ++j){
        while( (t > -1) and pat[t+1] != pat[j]){
            t = sbord[t]-1;
        }
        if( pat[t+1] == pat[j])
            t++;

        sbord[j] = t+1;
    }
    return sbord;
}

bool KMP(const string& text, const string& pat){
    int n = text.size()-1;
    int m = pat.size()-1;
    int i = 0, j = 0, occ = 0, k = 0;

    vector<int> bords = strong_borders(pat);

    while (n - k >= m)
    {
        while (j <= m and text[i] == pat[j]){
            ++j;
            ++i;
        }

        if (j > m and k+m == n)return true;

        if(j-1 >= 0 and bords[j-1] > 0) k = i - bords[j-1];

        else{
            if(i == k) i++;
            k = i;
        }

        if(j > 0) j = bords[j-1];
    }
    return false;
}

map <string, vs > mp;

void solve(string name){
	vector<string> base = mp[name];
	sort(base.begin(), base.end(), cmp);
	//cout << "o " << name << " ta ";
	//for(auto x: base) cout << " " << x;
	//	cout << endl;
	for(int i = 0; i < base.size(); i++){
		for(int j = 0; j < base.size(); j++){
			if(i != j and KMP(base[j],base[i]))/*cout << "deu o " << base[i] << " dentro do " << base[j] << endl, */base[i] = "", j = base.size();
		}
	}
	//cout << "base do " << name << " ficou " << endl;
	//for(auto x: base) cout << " " << x;
	//cout << endl;
	mp[name] = base;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n ; i++){
		string name;
		int qnt;
		cin >> name >> qnt;
		while(qnt--){
			string num;
			cin >> num;
			mp[name].pb(num);
		}
	}
	for(auto x : mp)solve(x.ff);
	cout << mp.size() << endl;
	for(auto x : mp){
		cout << x.ff << " ";
		int qnt = 0;
		for(auto y: x.ss) if(y != "") qnt++;
		cout << qnt;
		for(auto y: x.ss) if(y != "")cout << " " << y;

		puts("");
	}

}

// 1 2 3 4 5 6 7 8 9 10 11 12


#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define vs vector<string>
#define pb push_back

vector <int> strong_borders(const string& pat){
    int m = pat.size();
    vector <int> sbord(m);
    int t = -1;
    sbord[0] = 0;

    for (int j = 1; j < m; ++j){
        while( (t > -1) and pat[t+1] != pat[j]){
            t = sbord[t]-1;
        }
        if( pat[t+1] == pat[j])
            t++;

        sbord[j] = t+1;
    }
    return sbord;
}

bool KMP(const string& text, const string& pat){
    int n = text.size()-1;
    int m = pat.size()-1;
    int i = 0, j = 0, occ = 0, k = 0;

    vector<int> bords = strong_borders(pat);

    while (n - k >= m)
    {
        while (j <= m and text[i] == pat[j]){
            ++j;
            ++i;
        }

        if (j > m and k+m == n)return true;

        if(j-1 >= 0 and bords[j-1] > 0) k = i - bords[j-1];

        else{
            if(i == k) i++;
            k = i;
        }

        if(j > 0) j = bords[j-1];
    }
    return false;
}

map <string, vs > mp;

void solve(string name){
	vector<string> base = mp[name];
	sort(base.begin(), base.end());
	//cout << "o " << name << " ta ";
	//for(auto x: base) cout << " " << x;
	//cout << endl;
	for(int i = 0; i < base.size(); i++){
		for(int j = i+1; j < base.size(); j++){
			if(KMP(base[j],base[i])) base[i] = "";
		}
	}
	//cout << "base do " << name << " ficou " << endl;
	//for(auto x: base) cout << " " << x;
	//cout << endl;
	mp[name] = base;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n ; i++){
		string name;
		int qnt;
		cin >> name >> qnt;
		while(qnt--){
			string num;
			cin >> num;
			mp[name].pb(num);
		}
	}
	for(auto x : mp) solve(x.ff);
	cout << mp.size() << endl;
	for(auto x : mp){
		cout << x.ff << " ";
		int qnt = 0;
		for(auto y: x.ss) if(y != "") qnt++;
		cout << qnt;
		for(auto y: x.ss) if(y != "")cout << " " << y;

		puts("");
	}

}

// 1 2 3 4 5 6 7 8 9 10 11 12


#include<bits/stdc++.h>
using namespace std;
main () {
	long long n,m,i=1,i1=0,s1=0;
	string s[111111],a;
	map<string ,long long> m1;
	map<string , vector<string> > v;
	map<string , vector<string> >::iterator it;
	cin>>n;
	while(n--){
		cin>>s[i]>>m;
		if(m1[s[i]]==0) s1++;
		m1[s[i]]++;
		while(m--){
			cin>>a;
			for(i1=0;i1<v[s[i]].size();i1++){
				int i2=a.size()-1;
				int i3=v[s[i]][i1].size()-1;
				while(i2>=0 && i3>=0){
					if(v[s[i]][i1][i3]==a[i2]) {
						i2--;
						i3--;
					}
					else break;
				}
				if(i2==-1 || i3==-1){
					if(i3==-1){
						v[s[i]][i1]=a;
						break;
					}
					else break;
				}
			}
			if(i1==v[s[i]].size()) v[s[i]].push_back(a);
		}
		i++;
	}
	cout<<s1<<endl;
	for(it=v.begin();it!=v.end();it++){
		cout<<it->first<<" "<<it->second.size()<<" ";
		for(int i2=0;i2<it->second.size();i2++){
			cout<<it->second[i2]<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
main () {
	long long n,m,i=1,i1=0,s1=0;
	string s[111111],a;
	map<string ,long long> m1;
	map<string , vector<string> > v;
	map<string , vector<string> >::iterator it;
	cin>>n;
	while(n--){
		cin>>s[i]>>m;
		if(m1[s[i]]==0) s1++;
		m1[s[i]]++;
		while(m--){
			cin>>a;
			for(i1=0;i1<v[s[i]].size();i1++){
				int i2=a.size()-1;
				int i3=v[s[i]][i1].size()-1;
				while(i2>=0 && i3>=0){
					if(v[s[i]][i1][i3]==a[i2]) {
						i2--;
						i3--;
					}
					else break;
				}
				if(i2==-1 || i3==-1){
					if(i3==-1){
						v[s[i]].pop_back();
						v[s[i]].push_back(a);
						break;
					}
					else break;
				}
			}
			if(v[s[i]].size()==i1) v[s[i]].push_back(a);
		}
		i++;
	}
	cout<<s1<<endl;
	for(it=v.begin();it!=v.end();it++){
		cout<<it->first<<" "<<it->second.size()<<" ";
		for(int i2=0;i2<it->second.size();i2++){
			cout<<it->second[i2]<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
main () {
	long long n,m,i=1,i1=0,s1=0;
	string s[111111],a;
	map<string ,long long> m1;
	map<string , vector<string> > v;
	map<string , vector<string> >::iterator it;
	cin>>n;
	while(n--){
		cin>>s[i]>>m;
		if(m1[s[i]]==0) s1++;
		m1[s[i]]++;
		while(m--){
			cin>>a;
			for(i1=0;i1<v[s[i]].size();i1++){
				int i2=a.size()-1;
				int i3=v[s[i]][i1].size()-1;
				while(i2>=0 && i3>=0){
					if(v[s[i]][i1][i3]==a[i2]) {
						i2--;
						i3--;
					}
					else break;
				}
				if(i2==-1 || i3==-1){
					if(i3==-1){
						v[s[i]].pop_back();
						v[s[i]].push_back(a);
						break;
					}
					else break;
				}
			}
			if(v[s[i]][v[s[i]].size()-1]==a) continue;
			if(v[s[i]].size()==i1) v[s[i]].push_back(a);
		}
		i++;
	}
	cout<<s1<<endl;
	for(it=v.begin();it!=v.end();it++){
		cout<<it->first<<" "<<it->second.size()<<" ";
		for(int i2=0;i2<it->second.size();i2++){
			cout<<it->second[i2]<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
main () {
	long long n,m,i=1,i1=0,x,y,s1=0;
	string s[111111],a;
	map<string ,long long> m1;
	map<string , vector<string> > v;
	map<string , vector<string> >::iterator it;
	cin>>n;
	while(n--){
		cin>>s[i]>>m;
		if(m1[s[i]]==0) s1++;
		m1[s[i]]++;
		while(m--){
			cin>>a;
			for(i1=0;i1<v[s[i]].size();i1++){
				int i2=a.size()-1;
				int i3=v[s[i]][i1].size()-1;
				while(i2>=0 && i3>=0){
					if(v[s[i]][i1][i3]==a[i2]) {
						i2--;
						i3--;
					}
					else break;
				}
				if(i2==-1 || i3==-1) break;
			}
			if(i1==v[s[i]].size()) v[s[i]].push_back(a);
		}
		i++;
	}
	cout<<s1<<endl;
	for(it=v.begin();it!=v.end();it++){
		cout<<it->first<<" "<<it->second.size()<<" ";
		for(int i2=0;i2<it->second.size();i2++){
			cout<<it->second[i2]<<" ";
		}
		cout<<endl;
	}
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int cnt;
map <string, int> id;
map <string, bool> used[25];
map <int, string> myname;
vector <string> vec[25];

int main() {
  int n;
  cin >> n;
  for (int x = 0; x < n; x++) {
    int q;
    string name;
    cin >> name >> q;
    if (!id[name]) {
      id[name] = ++cnt;
      myname[id[name]] = name;
    }
    for (int j = 0; j < q; j++) {
      string num;
      cin >> num;
      if (!used[id[name]][num]) {
        vec[id[name]].push_back(num);
      }
      for (int i = 0; i < num.size(); i++) {
        used[id[name]][num.substr(i)] = 1;
      }
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= cnt; i++) {
    cout << myname[i] << " " << vec[i].size() << " ";
    for (string s : vec[i]) {
      cout << s << " ";
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int cnt;
map <string, int> id;
map <string, bool> used[25];
map <int, string> myname;
vector <bool> take[25];
vector <string> vec[25];

bool issuff(string a, string b) {
  if (a.size() > b.size()) {
    return 0;
  }
  int p = b.size() - a.size();
  int ok = 1;
  for (int i = p; i < b.size(); i++) {
    ok &= (b[i] == a[i - p]);
  }
  return ok;
}

int main() {
  int n;
  cin >> n;
  for (int x = 0; x < n; x++) {
    int q;
    string name;
    cin >> name >> q;
    if (!id[name]) {
      id[name] = ++cnt;
      myname[id[name]] = name;
    }
    for (int j = 0; j < q; j++) {
      string num;
      cin >> num;
      vec[id[name]].push_back(num);
      take[id[name]].push_back(1);
    }
  }
  for (int c = 1; c <= cnt; c++) {
    for (int i = 0; i < vec[c].size(); i++) {
      for (int j = i + 1; j < vec[c].size(); j++) {
        if (!take[c][i] || !take[c][j]) continue;
        if (issuff(vec[c][i], vec[c][j])) {
          take[c][i] = 0;
        }
        if (issuff(vec[c][j], vec[c][i])) {
          take[c][j] = 0;
        }
      }
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= cnt; i++) {
    cout << myname[i] << " ";
    int ce = 0;
    for (bool j : take[i]) {
      ce += j;
    }
    cout << ce << " ";
    for (int j = 0; j < vec[i].size(); j++) {
      if (take[i][j]) {
        cout << vec[i][j] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int cnt;
map <string, int> id;
map <string, bool> used[25];
map <int, string> myname;
vector <string> vec[25];

int main() {
  int n;
  cin >> n;
  for (int x = 0; x < n; x++) {
    int q;
    string name;
    cin >> name >> q;
    if (!id[name]) {
      id[name] = ++cnt;
      myname[id[name]] = name;
    }
    for (int j = 0; j < q; j++) {
      string num;
      cin >> num;
      if (!used[id[name]][num]) {
        vec[id[name]].push_back(num);
        for (int i = 0; i < num.size(); i++) {
          used[id[name]][num.substr(i)] = 1;
        }
      }
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= cnt; i++) {
    cout << myname[i] << " " << vec[i].size() << " ";
    for (string s : vec[i]) {
      cout << s << " ";
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int cnt;
map <string, int> id;
map <string, bool> used[25];
map <int, string> myname;
vector <string> vec[25];

inline bool cmp(string a, string b) {
  return (a.size() > b.size());
}

int main() {
  int n;
  cin >> n;
  for (int x = 0; x < n; x++) {
    int q;
    string name;
    cin >> name >> q;
    if (!id[name]) {
      id[name] = ++cnt;
      myname[id[name]] = name;
    }
    vector <string> here;
    for (int j = 0; j < q; j++) {
      string num;
      cin >> num;
      here.push_back(num);
    }
    sort(here.begin(), here.end(), cmp);
    string num;
    for (int j = 0; j < here.size(); j++) {
      num = here[j];
      if (!used[id[name]][num]) {
        vec[id[name]].push_back(num);
        for (int i = 0; i < num.size(); i++) {
          used[id[name]][num.substr(i)] = 1;
        }
      }
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= cnt; i++) {
    cout << myname[i] << " " << vec[i].size() << " ";
    for (string s : vec[i]) {
      cout << s << " ";
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int cnt;
map <string, int> id;
map <string, bool> used[25];
map <int, string> myname;
vector <string> vec[25];
vector <string> ans[25];

bool cmp(string a, string b) {
  return (a.size() > b.size());
}

int main() {
  int n;
  cin >> n;
  for (int x = 0; x < n; x++) {
    int q;
    string name;
    cin >> name >> q;
    if (!id[name]) {
      id[name] = ++cnt;
      myname[id[name]] = name;
    }
    for (int j = 0; j < q; j++) {
      string num;
      cin >> num;
      vec[id[name]].push_back(num);
    }
  }
  for (int i = 1; i <= cnt; i++) {
    sort(vec[i].begin(), vec[i].end(), cmp);
  }
  for (int i = 1; i <= cnt; i++) {
    for (string s : vec[i]) {
      if (!used[i][s]) {
        used[i][s] = 1;
        ans[i].push_back(s);
        for (int j = 0; j < s.size(); j++) {
          used[i][s.substr(j)] = 1;
        }
      }
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= cnt; i++) {
    cout << myname[i] << " " << ans[i].size() << " ";
    for (string s : ans[i]) {
      cout << s << " ";
    }
    cout << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
vector<ll> vec[15];
int visit[50];
struct node{
    string a;
    vector<string> num;
    int avail[3000];
    int n;
};
int func(string a, string b){
    int n = b.length()-1;
    int m = a.length();
    for(int i = a.length()-1; i>=0;i--){
        if(a[i] != b[n-(m-1-i)])
         return 0;
    }
    return 1;
}
int main(){
   ll i,j,n,m,val,fir,sec,thr,k;
   string vall;
   struct node arr[21];
   string temp;
   cin>>n;
   int ptr = 0;
   for(i=0;i<n;i++){
       cin>>temp;
       //cout<<temp<<"\n";
       for(j=0;j<ptr;j++){
           if(temp ==  arr[j].a){
               cin>>val;
               //cout<<val<<"\n";
               for(k=0;k<val;k++){
                   cin>>vall;
                   //cout<<vall<<"\n";
                   arr[j].num.push_back(vall);
               }
               break;
           }
       }
       if(j == ptr){
           arr[ptr].a = temp;
           cin>>val;
           //cout<<val<<"\n";
           for(k=0;k<val;k++){
               cin>>vall;
               //cout<<vall<<"\n";
               arr[ptr].num.push_back(vall);
           }
           ptr++;
       }
   }
  for(i=0;i<ptr;i++){
      for(j=0;j<arr[i].num.size()-1;j++){
          for(k=j+1;k<arr[i].num.size();k++){
              if(arr[i].num[j].length() > arr[i].num[k].length()){
                  temp = arr[i].num[k];
                  arr[i].num[k] = arr[i].num[j];
                  arr[i].num[j] = temp;
              }
          }
      }
  }
  for(i=0;i<ptr;i++){
      memset(arr[i].avail,0,sizeof(arr[i].avail));
      //cout<<"SIZE "<<arr[i].num.size()<<"\n";
      for(j=0;j<arr[i].num.size();j++){
          for(k = j+1; k<arr[i].num.size();k++){
              if(func(arr[i].num[j], arr[i].num[k]) == 1){
                  arr[i].avail[j] = 1;
              }
          }
      }
  }
  cout<<ptr<<"\n";
  for(i=0;i<ptr;i++){
      cout<<arr[i].a<<" ";
      int sum = 0;
      for(j=0;j<arr[i].num.size();j++){
          if(arr[i].avail[j] == 0)
            sum++;
      }
      cout<<sum<<" ";
      for(j=0;j<arr[i].num.size();j++){
          if(arr[i].avail[j] == 0)
          cout<<arr[i].num[j]<<" ";
      }
      cout<<"\n";
  }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
vector<ll> vec[15];
int visit[50];
struct node{
    string a;
    vector<string> num;
    int avail[50];
    int n;
};
int func(string a, string b){
    int n = b.length()-1;
    int m = a.length();
    for(int i = a.length()-1; i>=0;i--){
        if(a[i] != b[n-(m-1-i)])
         return 0;
    }
    return 1;
}
int main(){
   ll i,j,n,m,val,fir,sec,thr,k;
   string vall;
   struct node arr[15];
   string temp;
   cin>>n;
   int ptr = 0;
   for(i=0;i<n;i++){
       cin>>temp;
       //cout<<temp<<"\n";
       for(j=0;j<ptr;j++){
           if(temp ==  arr[j].a){
               cin>>val;
               //cout<<val<<"\n";
               for(k=0;k<val;k++){
                   cin>>vall;
                   //cout<<vall<<"\n";
                   arr[j].num.push_back(vall);
               }
               break;
           }
       }
       if(j == ptr){
           arr[ptr].a = temp;
           cin>>val;
           //cout<<val<<"\n";
           for(k=0;k<val;k++){
               cin>>vall;
               //cout<<vall<<"\n";
               arr[ptr].num.push_back(vall);
           }
           ptr++;
       }
   }
   for(i=0;i<ptr;i++){
       for(j=0;j<arr[i].num.size()-1;j++){
           for(k=j+1;k<arr[i].num.size();k++){
               if(arr[i].num[j].length() > arr[i].num[k].length()){
                   temp = arr[i].num[k];
                   arr[i].num[k] = arr[i].num[j];
                   arr[i].num[j] = temp;
               }
           }
       }
   }
   for(i=0;i<ptr;i++){
       memset(arr[i].avail,0,sizeof(arr[i].avail));
       for(j=0;j<arr[i].num.size();j++){
           for(k = j+1; k<arr[i].num.size();k++){
               if(func(arr[i].num[j], arr[i].num[k]) == 1){
                   arr[i].avail[j] = 1;
               }
           }
       }
   }
   cout<<ptr<<"\n";
   for(i=0;i<ptr;i++){
       cout<<arr[i].a<<" ";
       int sum = 0;
       for(j=0;j<arr[i].num.size();j++){
           if(arr[i].avail[j] == 0)
            sum++;
       }
       cout<<sum<<" ";
       for(j=0;j<arr[i].num.size();j++){
           if(arr[i].avail[j] == 0)
           cout<<arr[i].num[j]<<" ";
       }
       cout<<"\n";
   }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
vector<ll> vec[100005];
int visit[100005];
struct node{
    string a;
    vector<string> num;
    int avail[10000];
    int n;
};
int func(string a, string b){
    int n = b.length()-1;
    int m = a.length();
    for(int i = a.length()-1; i>=0;i--){
        if(a[i] != b[n-(m-1-i)])
         return 0;
    }
    return 1;
}
int main(){
   ll i,j,n,m,val,fir,sec,thr,k;
   string vall;
   struct node arr[10000];
   string temp;
   cin>>n;
   int ptr = 0;
   for(i=0;i<n;i++){
       cin>>temp;
       //cout<<temp<<"\n";
       for(j=0;j<ptr;j++){
           if(temp ==  arr[j].a){
               cin>>val;
               //cout<<val<<"\n";
               for(k=0;k<val;k++){
                   cin>>vall;
                   //cout<<vall<<"\n";
                   arr[j].num.push_back(vall);
               }
               break;
           }
       }
       if(j == ptr){
           arr[ptr].a = temp;
           cin>>val;
           //cout<<val<<"\n";
           for(k=0;k<val;k++){
               cin>>vall;
               //cout<<vall<<"\n";
               arr[ptr].num.push_back(vall);
           }
           ptr++;
       }
   }
   for(i=0;i<ptr;i++){
       for(j=0;j<arr[i].num.size()-1;j++){
           for(k=j+1;k<arr[i].num.size();k++){
               if(arr[i].num[j].length() > arr[i].num[k].length()){
                   temp = arr[i].num[k];
                   arr[i].num[k] = arr[i].num[j];
                   arr[i].num[j] = temp;
               }
           }
       }
   }
   for(i=0;i<ptr;i++){
       memset(arr[i].avail,0,sizeof(arr[i].avail));
       for(j=0;j<arr[i].num.size();j++){
           for(k = j+1; k<arr[i].num.size();k++){
               if(func(arr[i].num[j], arr[i].num[k]) == 1){
                   arr[i].avail[j] = 1;
               }
           }
       }
   }
   cout<<ptr<<"\n";
   for(i=0;i<ptr;i++){
       cout<<arr[i].a<<" ";
       int sum = 0;
       for(j=0;j<arr[i].num.size();j++){
           if(arr[i].avail[j] == 0)
            sum++;
       }
       cout<<sum<<" ";
       for(j=0;j<arr[i].num.size();j++){
           if(arr[i].avail[j] == 0)
           cout<<arr[i].num[j]<<" ";
       }
       cout<<"\n";
   }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
vector<ll> vec[15];
int visit[50];
struct node{
    string a;
    vector<string> num;
    int avail[3000];
    int n;
};
int func(string a, string b){
    int n = b.length()-1;
    int m = a.length();
    for(int i = a.length()-1; i>=0;i--){
        if(a[i] != b[n-(m-1-i)])
         return 0;
    }
    return 1;
}
int main(){
   ll i,j,n,m,val,fir,sec,thr,k;
   string vall;
   struct node arr[15];
   string temp;
   cin>>n;
   int ptr = 0;
   for(i=0;i<n;i++){
       cin>>temp;
       //cout<<temp<<"\n";
       for(j=0;j<ptr;j++){
           if(temp ==  arr[j].a){
               cin>>val;
               //cout<<val<<"\n";
               for(k=0;k<val;k++){
                   cin>>vall;
                   //cout<<vall<<"\n";
                   arr[j].num.push_back(vall);
               }
               break;
           }
       }
       if(j == ptr){
           arr[ptr].a = temp;
           cin>>val;
           //cout<<val<<"\n";
           for(k=0;k<val;k++){
               cin>>vall;
               //cout<<vall<<"\n";
               arr[ptr].num.push_back(vall);
           }
           ptr++;
       }
   }
  for(i=0;i<ptr;i++){
      for(j=0;j<arr[i].num.size()-1;j++){
          for(k=j+1;k<arr[i].num.size();k++){
              if(arr[i].num[j].length() > arr[i].num[k].length()){
                  temp = arr[i].num[k];
                  arr[i].num[k] = arr[i].num[j];
                  arr[i].num[j] = temp;
              }
          }
      }
  }
  for(i=0;i<ptr;i++){
      memset(arr[i].avail,0,sizeof(arr[i].avail));
      //cout<<"SIZE "<<arr[i].num.size()<<"\n";
      for(j=0;j<arr[i].num.size();j++){
          for(k = j+1; k<arr[i].num.size();k++){
              if(func(arr[i].num[j], arr[i].num[k]) == 1){
                  arr[i].avail[j] = 1;
              }
          }
      }
  }
  cout<<ptr<<"\n";
  for(i=0;i<ptr;i++){
      cout<<arr[i].a<<" ";
      int sum = 0;
      for(j=0;j<arr[i].num.size();j++){
          if(arr[i].avail[j] == 0)
            sum++;
      }
      cout<<sum<<" ";
      for(j=0;j<arr[i].num.size();j++){
          if(arr[i].avail[j] == 0)
          cout<<arr[i].num[j]<<" ";
      }
      cout<<"\n";
  }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
const long long  linf=1e18;
const int mod=1e9+7;
map <string,int>mp;
map <int,string>mp2;
vector<string>phone[500];
//int cnt[500];
bool check(int index,string s)
{
    if(phone[index].size()==0)return true;
    int flag=0;
    for(int i=0; i<phone[index].size(); i++)
    {
        flag=0;
        string k=phone[index][i];
        int j=k.size()-1;
        int p=s.size()-1;
        while(j>=0&&p>=0)
        {
            if(s[p]!=k[j])
            {
                flag=1;
            }
            j--;
            p--;
        }

        if(p>j&&!flag)
        {
            vector<string>::iterator   iter   =   phone[index].begin()+i;
            phone[index].erase(iter);
            return true;
        }
        else if (!flag)
        {
            return false;
        }
    }
    return true;
}
struct cmp1
{
    int id;
    int cnt;
} a[100];

bool cmp(cmp1 a,cmp1 b)
{
    return a.cnt<b.cnt;
}
int main()
{
    int n;
    cin>>n;
    int t=0;
    //memset(cnt,0,sizeof(cnt));
    mp.clear();
    for(int pp=1; pp<=n; pp++)
    {
        string s;
        int num;
        cin>>s>>num;
        if(!mp[s])
        {
        mp[s]=++t;
        mp2[t]=s;
        }
        //cout<<"--"<<t<<" "<<mp2[t]<<endl;
        int index=mp[s];
        //cnt[index]+=num;
        for(int j=1; j<=num; j++)
        {
            string s1;
            cin>>s1;
            //cout<<s1<<endl;
            if(check(index,s1))
                phone[index].push_back(s1);
            int r=phone[index].size()-1;
            //cout<<r<<" "<<phone[index][r]<<endl;
        }
    }
    for(int i=1; i<=t; i++)
    {
        cmp1 temp;
        temp.id=i;
        temp.cnt=phone[i].size();
        a[i]=temp;
    }
    sort(a+1,a+1+t,cmp);
    cout<<t<<endl;
    for(int i=1; i<=t; i++)
    {
        int m=a[i].id;
        cout<<mp2[m]<<" "<<a[i].cnt<<" ";
        for(int j=0; j<a[i].cnt; j++)
        {
            if(j==a[i].cnt-1)cout<<phone[m][j]<<endl;
            else
                cout<<phone[m][j]<<" ";
        }
        //cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
const long long  linf=1e18;
const int mod=1e9+7;
map <string,int>mp;
map <int,string>mp2;
vector<string>phone[500];
//int cnt[500];
bool check(int index,string s)
{
    if(phone[index].size()==0)return true;
    int flag=0;
    for(int i=0; i<phone[index].size(); i++)
    {
        flag=0;
        string k=phone[index][i];
        int j=k.size()-1;
        int p=s.size()-1;
        while(j>=0&&p>=0)
        {
            if(s[p]!=k[j])
            {
                flag=1;
            }
            j--;
            p--;
        }

        if(p>j&&!flag)
        {
            vector<string>::iterator   iter   =   phone[index].begin()+i;
            phone[index].erase(iter);
            return true;
        }
        else if (!flag)
        {
            return false;
        }
    }
    return true;
}
struct cmp1
{
    int id;
    int cnt;
} a[100];

bool cmp(cmp1 a,cmp1 b)
{
    return a.cnt<b.cnt;
}
int main()
{
    int n;
    cin>>n;
    int t=0;
    //memset(cnt,0,sizeof(cnt));
    mp.clear();
    for(int pp=1; pp<=n; pp++)
    {
        string s;
        int num;
        cin>>s>>num;
        if(!mp[s])
            mp[s]=++t;
        mp2[t]=s;
        int index=mp[s];
        //cnt[index]+=num;
        for(int j=1; j<=num; j++)
        {
            string s1;
            cin>>s1;
            //cout<<s1<<endl;
            if(check(index,s1))
                phone[index].push_back(s1);
            int r=phone[index].size()-1;
            //cout<<r<<" "<<phone[index][r]<<endl;
        }
    }
    for(int i=1; i<=t; i++)
    {
        cmp1 temp;
        temp.id=i;
        temp.cnt=phone[i].size();
        a[i]=temp;
    }
    sort(a+1,a+1+t,cmp);
    for(int i=1; i<=t; i++)
    {
        int m=a[i].id;
        cout<<mp2[m]<<" "<<a[i].cnt<<" ";
        for(int j=0; j<a[i].cnt; j++)
        {
            if(j==a[i].cnt-1)cout<<phone[m][j];
            else
                cout<<phone[m][j]<<" ";
        }
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
const long long  linf=1e18;
const int mod=1e9+7;
map <string,int>mp;
map <int,string>mp2;
vector<string>phone[500];
//int cnt[500];
bool check(int index,string s)
{
    if(phone[index].size()==0)return true;
    int flag=0;
    for(int i=0; i<phone[index].size(); i++)
    {
        flag=0;
        string k=phone[index][i];
        int j=k.size()-1;
        int p=s.size()-1;
        while(j>=0&&p>=0)
        {
            if(s[p]!=k[j])
            {
                flag=1;
            }
            j--;
            p--;
        }

        if(p>j&&!flag)
        {
            vector<string>::iterator   iter   =   phone[index].begin()+i;
            phone[index].erase(iter);
            return true;
        }
        else if (!flag)
        {
            return false;
        }
    }
    return true;
}
struct cmp1
{
    int id;
    int cnt;
} a[100];

bool cmp(cmp1 a,cmp1 b)
{
    return a.cnt<b.cnt;
}
int main()
{
    int n;
    cin>>n;
    int t=0;
    //memset(cnt,0,sizeof(cnt));
    mp.clear();
    for(int pp=1; pp<=n; pp++)
    {
        string s;
        int num;
        cin>>s>>num;
        if(!mp[s])
            mp[s]=++t;
        mp2[t]=s;
        int index=mp[s];
        //cnt[index]+=num;
        for(int j=1; j<=num; j++)
        {
            string s1;
            cin>>s1;
            //cout<<s1<<endl;
            if(check(index,s1))
                phone[index].push_back(s1);
            int r=phone[index].size()-1;
            //cout<<r<<" "<<phone[index][r]<<endl;
        }
    }
    for(int i=1; i<=t; i++)
    {
        cmp1 temp;
        temp.id=i;
        temp.cnt=phone[i].size();
        a[i]=temp;
    }
    sort(a+1,a+1+t,cmp);
    cout<<t<<endl;
    for(int i=1; i<=t; i++)
    {
        int m=a[i].id;
        cout<<mp2[m]<<" "<<a[i].cnt<<" ";
        for(int j=0; j<a[i].cnt; j++)
        {
            if(j==a[i].cnt-1)cout<<phone[m][j]<<endl;
            else
                cout<<phone[m][j]<<" ";
        }
        //cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
const long long  linf=1e18;
const int mod=1e9+7;
map <string,int>mp;
map <int,string>mp2;
vector<string>phone[500];
//int cnt[500];
bool check(int index,string s)
{
    if(phone[index].size()==0)return true;
    int flag=0;
    for(int i=0; i<phone[index].size(); i++)
    {
        flag=0;
        string k=phone[index][i];
        int j=k.size()-1;
        int p=s.size()-1;
        while(j>=0&&p>=0)
        {
            if(s[p]!=k[j])
            {
                flag=1;
            }
            j--;
            p--;
        }

        if(p>j&&!flag)
        {
            vector<string>::iterator   iter   =   phone[index].begin()+i;
            phone[index].erase(iter);
            return true;
        }
        else if (!flag)
        {
            return false;
        }
    }
    return true;
}
struct cmp1
{
    int id;
    int cnt;
} a[100];

bool cmp(cmp1 a,cmp1 b)
{
    return a.cnt<b.cnt;
}
int main()
{
    int n;
    cin>>n;
    int t=0;
    //memset(cnt,0,sizeof(cnt));
    mp.clear();
    for(int pp=1; pp<=n; pp++)
    {
        string s;
        int num;
        cin>>s>>num;
        if(!mp[s])
            mp[s]=++t;
        mp2[t]=s;
        int index=mp[s];
        //cnt[index]+=num;
        for(int j=1; j<=num; j++)
        {
            string s1;
            cin>>s1;
            //cout<<s1<<endl;
            if(check(index,s1))
                phone[index].push_back(s1);
            int r=phone[index].size()-1;
            //cout<<r<<" "<<phone[index][r]<<endl;
        }
    }
    for(int i=1; i<=t; i++)
    {
        cmp1 temp;
        temp.id=i;
        temp.cnt=phone[i].size();
        a[i]=temp;
    }
    sort(a+1,a+1+t,cmp);
    for(int i=1; i<=t; i++)
    {
        int m=a[i].id;
        cout<<mp2[m]<<" "<<a[i].cnt<<" ";
        for(int j=0; j<a[i].cnt; j++)
        {
            if(j==a[i].cnt-1)cout<<phone[m][j]<<endl;
            else
                cout<<phone[m][j]<<" ";
        }
        //cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<pair<string,vector<string> > > v,ans;

bool isSuffix(string S, string G){
    string suffix = G.substr(G.size()-S.size());
    return (suffix == S);
}
bool Sort(string &s1 , string &s2){
    return s1.size() < s2.size();
}
int main()
{
    int n; cin>>n;
    while(n--){
        string name; cin>>name;
        int N; cin>>N;
        bool found = 0;
        for (int i = 0 ; i < v.size(); ++i){
            if (v[i].first == name){
                while(N--){
                        string p; cin>>p;
                    v[i].second.push_back(p);
                }
                found = 1;
                break;
            }
        }
        if (!found){
         vector <string> V;
         v.push_back({name,V});
         while(N--){
                    string p; cin>>p;
                    v.back().second.push_back(p);
                }
        }
    }

     for (int i= 0 ; i < v.size() ;++i){
            vector <string> tmp = v[i].second;
            sort(tmp.begin(),tmp.end(),Sort);
            v[i].second = tmp;
    }

    for(int i = 0 ; i < v.size(); ++i){
            vector<string> temp;
        for (int k = 0 ; k < v[i].second.size() ; ++k){
                bool taken = 0 ;
            for (int j = k+1 ; j < v[i].second.size() ; ++j){
                    string F = v[i].second[k] , S = v[i].second[j];
                     if (k != j && F.size() <= S.size()){
                        if (isSuffix(F,S)){
                            taken = 1;
                            break;
                        }
                     }
                }
                if (!taken){
                    temp.push_back(v[i].second[k]);
                }
        }
        ans.push_back({v[i].first,temp});
    }
    cout << ans.size() << endl;
    for (int i= 0 ; i < ans.size() ;++i){
            cout << ans[i].first << " " << ans[i].second.size() << " ";
        for (int k = 0 ; k < ans[i].second.size(); ++k){
            cout << ans[i].second[k] << " ";
        }
    cout << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<pair<string,vector<string> > > v,ans;

bool isSuffix(string S, string G){
    string suffix = G.substr(G.size()-S.size());
    return (suffix == S);
}
int main()
{
    int n; cin>>n;
    while(n--){
        string name; cin>>name;
        int N; cin>>N;
        bool found = 0;
        for (int i = 0 ; i < v.size(); ++i){
            if (v[i].first == name){
                while(N--){
                        string p; cin>>p;
                    v[i].second.push_back(p);
                }
                found = 1;
                break;
            }
        }
        if (!found){
         vector <string> V;
         v.push_back({name,V});
         while(N--){
                    string p; cin>>p;
                    v.back().second.push_back(p);
                }
        }
    }

    for(int i = 0 ; i < v.size(); ++i){
            vector<string> temp;
        for (int k = 0 ; k < v[i].second.size() ; ++k){
                bool taken = 0 ;
            for (int j = k+1 ; j < v[i].second.size() ; ++j){
                    string F = v[i].second[k] , S = v[i].second[j];
                     if (k != j && F.size() <= S.size()){
                        if (isSuffix(F,S)){
                            taken = 1;
                            break;
                        }
                     }
                }
                if (!taken){
                    temp.push_back(v[i].second[k]);
                }
        }
        ans.push_back({v[i].first,temp});
    }
    cout << ans.size() << endl;
    for (int i= 0 ; i < ans.size() ;++i){
            cout << ans[i].first << " " << ans[i].second.size() << " ";
        for (int k = 0 ; k < ans[i].second.size(); ++k){
            cout << ans[i].second[k] << " ";
        }
    cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<string,set<string> > m;
vector <pair<string,vector<string> > > ans;
bool Sort(string s1 , string s2){
    return s1.size() <= s2.size();
}

bool checkSuffix(string s, string p){
    bool f = 0;
    string Suffix = s.substr(s.size()-p.size());
    return Suffix == p;
}
int main()
{
    int n;
    cin>>n;
    for (int i = 0 ; i < n ; ++i){
        string name;
        cin>>name;
        int N;
        cin>>N;
        while(N--){
                string p; cin>>p;
            m[name].insert(p);
        }
    }
   map<string,set<string> > :: iterator it = m.begin();
   while(it != m.end()){
        vector<string> v;

    set<string> :: iterator phones = it->second.begin();
    while(phones != it->second.end()){
           v.push_back(*phones);
        phones++;
    }
    sort(v.begin(),v.end(),Sort);
    ans.push_back({it->first,v});

    it++;
   }

  for (int i = 0 ; i < ans.size() ;++i){

    for (int k = 0 ; k < ans[i].second.size() ;++k){

        for (int j = k+1 ; j < ans[i].second.size() ; ++j){
             if (k != j){
            string cr = ans[i].second[k];
            if ( checkSuffix(ans[i].second[j],cr)){
                ans[i].second[k] = "..";
                break;
            }
                }
        }
    }
   }
   vector <pair<string,vector<string> > > res;
    for (int i = 0 ; i < ans.size() ;++i){
        string name = ans[i].first;
        vector <string> all;
    for (int k = 0 ; k < ans[i].second.size() ;++k){
            if (ans[i].second[k] != "..")
                    all.push_back(ans[i].second[k]);
    }

    res.push_back({name,all});
   }

    for (int i = 0 ; i < res.size() ;++i){

        cout << res[i].first << " " << res[i].second.size() << " ";
    for (int k = 0 ; k < res[i].second.size() ;++k){
            cout << res[i].second[k] << " ";
    }
    cout <<endl;
   }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<pair<string,vector<string> > > v,ans;

bool isSuffix(string S, string G){
    string suffix = G.substr(G.size()-S.size());
    return (suffix == S);
}

int main()
{
    int n; cin>>n;
    while(n--){
        string name; cin>>name;
        int N; cin>>N;
        bool found = 0;
        for (int i = 0 ; i < v.size(); ++i){
            if (v[i].first == name){
                while(N--){
                        string p; cin>>p;
                    v[i].second.push_back(p);
                }
                found = 1;
                break;
            }
        }
        if (!found){
         vector <string> V;
         v.push_back({name,V});
         while(N--){
                    string p; cin>>p;
                    v.back().second.push_back(p);
                }
        }
    }

     for (int i= 0 ; i < v.size() ;++i){
            sort(v[i].second.begin(),v[i].second.end());
    }

    for(int i = 0 ; i < v.size(); ++i){
            vector<string> temp;
        for (int k = 0 ; k < v[i].second.size() ; ++k){
                bool taken = 0 ;
            for (int j = k+1 ; j < v[i].second.size() ; ++j){
                    string F = v[i].second[k] , S = v[i].second[j];
                     if (k != j && F.size() <= S.size()){
                        if (isSuffix(F,S)){
                            taken = 1;
                            break;
                        }
                     }
                }
                if (!taken){
                    temp.push_back(v[i].second[k]);
                }
        }
        ans.push_back({v[i].first,temp});
    }
    cout << ans.size() << endl;
    for (int i= 0 ; i < ans.size() ;++i){
            cout << ans[i].first << " " << ans[i].second.size() << " ";
        for (int k = 0 ; k < ans[i].second.size(); ++k){
            cout << ans[i].second[k] << " ";
        }
    cout << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<pair<string,vector<string> > > v,ans;

bool isSuffix(string S, string G){
    string suffix = G.substr(G.size()-S.size());
    return (suffix == S);
}
bool Sort(string s1 , string s2){
    return s1.size() <= s2.size();
}
int main()
{
    int n; cin>>n;
    while(n--){
        string name; cin>>name;
        int N; cin>>N;
        bool found = 0;
        for (int i = 0 ; i < v.size(); ++i){
            if (v[i].first == name){
                while(N--){
                        string p; cin>>p;
                    v[i].second.push_back(p);
                }
                found = 1;
                break;
            }
        }
        if (!found){
         vector <string> V;
         v.push_back({name,V});
         while(N--){
                    string p; cin>>p;
                    v.back().second.push_back(p);
                }
        }
        sort(v.back().second.begin(),v.back().second.end(),Sort);
    }

    for(int i = 0 ; i < v.size(); ++i){
            vector<string> temp;
        for (int k = 0 ; k < v[i].second.size() ; ++k){
                bool taken = 0 ;
            for (int j = k+1 ; j < v[i].second.size() ; ++j){
                    string F = v[i].second[k] , S = v[i].second[j];
                     if (k != j){
                        if (isSuffix(F,S)){
                            taken = 1;
                            break;
                        }
                     }
                }
                if (!taken){
                    temp.push_back(v[i].second[k]);
                }
        }
        ans.push_back({v[i].first,temp});
    }
    for (int i= 0 ; i < ans.size() ;++i){
            cout << ans[i].first << " " << ans[i].second.size() << " ";
        for (int k = 0 ; k < ans[i].second.size(); ++k){
            cout << ans[i].second[k] << " ";
        }
    cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<string,set<string> > m;
vector <pair<string,vector<string> > > ans;
bool Sort(string s1 , string s2){
    return s1.size() <= s2.size();
}

bool checkSuffix(string s, string p){
    bool f = 0;
    string Suffix = s.substr(s.size()-p.size());
    return Suffix == p;
}
int main()
{
    int n;
    cin>>n;
    for (int i = 0 ; i < n ; ++i){
        string name;
        cin>>name;
        int N;
        cin>>N;
        while(N--){
                string p; cin>>p;
            m[name].insert(p);
        }
    }
   map<string,set<string> > :: iterator it = m.begin();
   while(it != m.end()){
        vector<string> v;

    set<string> :: iterator phones = it->second.begin();
    while(phones != it->second.end()){
           v.push_back(*phones);
        phones++;
    }
    sort(v.begin(),v.end(),Sort);
    ans.push_back({it->first,v});

    it++;
   }

  for (int i = 0 ; i < ans.size() ;++i){

    for (int k = 0 ; k < ans[i].second.size() ;++k){

        for (int j = k+1 ; j < ans[i].second.size() ; ++j){
             if (k != j){
            string cr = ans[i].second[k];
            if ( checkSuffix(ans[i].second[j],cr)){
                ans[i].second[k] = "..";
                break;
            }
                }
        }
    }
   }
   vector <pair<string,vector<string> > > res;
    for (int i = 0 ; i < ans.size() ;++i){
        string name = ans[i].first;
        vector <string> all;
    for (int k = 0 ; k < ans[i].second.size() ;++k){
            if (ans[i].second[k] != "..")
                    all.push_back(ans[i].second[k]);
    }

    res.push_back({name,all});
   }
   cout << res.size() << endl;
    for (int i = 0 ; i < res.size() ;++i){

        cout << res[i].first << " " << res[i].second.size() << " ";
    for (int k = 0 ; k < res[i].second.size() ;++k){
            cout << res[i].second[k] << " ";
    }
    cout <<endl;
   }
    return 0;
}


#include<bits/stdc++.h>
#include <algorithm>
#include<vector>
#include<list>
#include<utility>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long int
#define fill(a,v) memset(a,v,sizeof a)
#define FORN(i, n) for(i = 0; i < n; i++)
#define mp make_pair
#define pb push_back
#define s(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+(n))
#define ff first
#define ss second
#define elif else if
using namespace std;
ll i,j,n;
int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	vector<string>v[21];
	map<string,ll>mp;
	ll k=0;
	set<string>sz;
	for(i=0;i<n;i++)
	{
		string s,pno;
		ll no;
		cin>>s>>no;
		if(mp.find(s)==mp.end())
		{
			mp[s]=k;
			k++;
		}
		for(j=0;j<no;j++)
		{
			cin>>pno;
			v[mp[s]].pb(pno);
		}
		sz.insert(s);
	}
	set<string> :: iterator it;
	vector<string >keep;
	for(it=sz.begin();it!=sz.end();it++)
	{
		string t=*it;
		keep.pb(t);
	}
	cout<<sz.size()<<endl;

		vector< pair<ll,string> >v1;
	for( ll jj=0;jj<keep.size();jj++)
	{
		v1.clear();
		for(ll tt=0;tt<v[mp[keep[jj]]].size();tt++)
		{
			string p=v[mp[keep[jj]]][tt];
			v1.pb({p.size(),p});
		}
		sort(v1.begin(),v1.end(),greater<pair<ll,string> >());
		ll vis[21];
		fill(vis,0);

		cout<<keep[jj]<<" ";
		ll p=0;
		for(i=0;i<v1.size();i++)
		{
			if(!vis[i])
			{
				string t=v1[i].ss;
				ll len=v1[i].ff;
				for(j=i+1;j<v1.size();j++)
				{
					ll len2=v1[j].ff;
					string tt=v1[j].ss;
					if(t[len-1]==tt[len2-1])
						vis[j]=1;
				}
				p++;
			}
		}
		cout<<p<<" ";
		for(i=0;i<v1.size();i++)
		{
			if(!vis[i])
				cout<<v1[i].ss<<" ";
		}
		cout<<endl;
	}

  return 0;
  }


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
// #include <chrono>
// #include <string>
#include <algorithm>

using namespace std;
// using namespace std::chrono;

// typedef std::chrono::high_resolution_clock::time_point timen;
typedef long long ll;
typedef long double ld;

#define duration(a) std::chrono::duration_cast<std::chrono::nanoseconds>(a).count()
#define timeNow() std::chrono::high_resolution_clock::now()
#define f(i, n) for(int (i)=0; (i)<(n); (i)++)
#define frp(i, a, b) for(int (i)=a; (i)<(b); (i)++)
#define frn(i, a, b) for(int (i)=a; (i)>(b); (i)--)
#define pb(a) push_back(a)

#define p(aaa) cout<<"debug "<<aaa<<endl;
#define PI 3.14159265358979323846

const int mod=1e9+7;
const int mx=1e3;

struct s
{
	int v;
	int len;
	int rose;
	int lily;
	vector<int> adj;
};

int n, m, tl, tr;
vector<struct s> a;
vector<int> g;
vector<int> l, r, fri;

bool complen(const s &a, const s &b){
	return a.len<b.len;
}

void putflowers(int t, int p){

	while(!a[t].adj.empty()){
		// cout<<a[t].adj.back()<<endl;
		putflowers(a[t].adj.back(), t);
		a[t].adj.pop_back();
	}
	// check which location are filled, fill the remaining
	// subtract from a[p].rose and a[p].lily
	// check which locations are filled fill the remaining with a[p].rose and a[p].lily
	frp(j, l[a[t].v]-1, r[a[t].v]){
		// cout<<g[j]<<" "<<a[t].rose<<endl;
		if(g[j]==0) a[t].rose-=1;
		else if(g[j]==1) a[t].lily-=1;
		else{
			if(a[t].rose>0){g[j]=0; a[t].rose-=1;}
			else {g[j]=1; a[t].lily-=1;}
		}
		// cout<<j<<" "<<g[j]<<" "<<a[t].rose<<endl;

	}
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	s tmp;

	cin>>n>>m;
	f(i, n) g.pb(-1);

	f(i, m){
		cin>>tl>>tr;
		l.pb(tl);
		r.pb(tr);
		tmp.v=i;
		tmp.len=r[i]-l[i]+1;
		tmp.rose=(r[i]-l[i]+1)/2;
		tmp.lily=(r[i]-l[i]+2)/2;
		a.pb(tmp);
	}
	sort(a.begin(), a.end(), complen);

	f(i, m-1){
		int flag=0;
		frp(j, i+1, m){
			if(r[a[i].v]<=r[a[j].v] && l[a[i].v]>=l[a[j].v]){
			// cout<<r[a[i].v]<<" "<<r[a[j].v]<<" "<<l[a[i].v]<<" "<<l[a[j].v]<<endl;
				a[j].adj.pb(a[i].v);
				flag=1;
				break;
			}
		}
		if(flag==0) fri.pb(i);
	}
	fri.pb(m-1);
	// cout<<"hello"<<endl;
	f(i, fri.size()){
		// cout<<fri[i]<<endl;
		putflowers(fri[i], -1);
	}

	// f(i, n) if(g[i]==-1) g[i]=1;
	f(i, n) cout<<g[i];
	cout<<endl;
	return 0;
}