#pragma comment(linker, "/STACK:60000000")
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <sstream>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define norm(a) sort(all(a)), a.erase(unique(all(a)), a.end())
#define num(a,x) (int)(lower_bound(all(a), x) - a.begin())

typedef long long int64;
typedef pair <int, int> pii;
typedef long double ldb;

const long double eps = 1e-7;
const int inf = (1 << 30) - 1;
const int64 inf64 = ((int64)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
const string task = "voc";

template <class T> T sqr (T x) {return x * x;}

const int nmax = 100100;

char buf[2 * 1000 * 1000];

string s[nmax];
int n, m;
vector<int> e[nmax];
vector<string> res[nmax], g[nmax];
vector<string> w;

void solve(){
	m = 0;
	forn(i,n)
		forn(j, g[i].size())
			w.pb(g[i][j]);
	norm(w);
	m = w.size();
	forn(i,n)
		forn(j, g[i].size()){
			int cur = num(w, g[i][j]);
			res[cur].pb(s[i]);
		}
	forn(i,m)
		norm(res[i]);
}

void read(){
	scanf("%d\n", &n);
	forn(i,n){
		scanf("%s", buf);
		s[i] = buf;
		scanf("%s", buf);
		gets(buf);
		int w = strlen(buf)+1;
		buf[w-1] = ',';
		string now = "";
		forn(j,w){
			if (buf[j] == ','){
				if (now.size() > 0) g[i].pb(now);
				now = "";
				continue;
			}
			if (buf[j] != ' ') now = now + buf[j];
		}
	}
}			


void write_A(){
	cout << m << endl;
	forn(i, m){
		printf("%s\n%d\n", w[i].data(), (int)res[i].size());
		forn(j, res[i].size())
			printf("%s\n", res[i][j].data());
	}
}

void write_B(){
	cout << m << endl;
	forn(i, m){
		printf("%s - ",w[i].data());
		forn(j, res[i].size()){
			printf("%s", res[i][j].data());
			if (j + 1 < res[i].size())
				printf(", ");
		}
		printf("\n");
	}
}

int main ()
{
//	freopen ((task + ".in").data(), "r", stdin);
//	freopen ((task + ".out").data(), "w", stdout);

	read();
	solve();
	write_B();

	return 0;
}
