#include <iostream>
#include <set>
#include <map>

int main() {
  size_t n;
  std::string line;
  std::map<std::string, std::set<std::string>> d;
  
  std::cin >> n;
  std::getline(std::cin,line);
  
  while(n--)
  {
    std::getline(std::cin, line);
    
    size_t pos1{}, pos2{line.find("-")}, commas{1};
    
    for(char c: line) if(c == ',') ++commas;
    
    line+=',';

    std::string left(line, pos1, pos2-pos1-1), right(line, pos2+2, line.find(",", pos2+2)-pos2-2);
    
    if(d.find(right)==d.end()) d[right] = std::set<std::string>{};
    
    d[right].insert(left);
    
    while(commas--)
    {
      pos1 = pos2+2;
      pos2 = line.find(",", pos1);
      right = std::string(line, pos1, pos2-pos1);
      if(d.find(right)==d.end()) d[right] = std::set<std::string>{};
      d[right].insert(left);
    }
 
  }

  std::cout << d.size() << '\n';
  for(auto i: d)
  {
    std::cout << i.first << " - ";
    auto j {i.second.begin()};
    auto jp{j}; ++jp;
    for(; jp!=i.second.end(); ++j, ++jp)
      std::cout << *j << ", ";
    std::cout << *j << '\n';
  }
      
      
      
  return 0;
}