#!/usr/bin/python
import sys

data = open(sys.argv[1], 'r').readlines()
data = [line[:-1] for line in data]

links = []
depth = {}
link = {}

for line in data:
  if line.find('<TTGlyph') != -1:
    temp = line[line.find(' name="')+7:]
    temp = temp[:temp.find('"')]
    lastglyph = temp
    depth[lastglyph] = 1
  elif line.find('<component') != -1:
    temp = line[line.find(' glyphName="')+12:]
    temp = temp[:temp.find('"')]
    comp = temp
    links.append((lastglyph, comp))

finished = False
while not finished:
  finished = True
  for a, b in links:
    if depth[a] <= depth[b]:
      depth[a] = depth[b]+1
      link[a] = b
      finished = False

m = max(depth.values())
print m

found = ''
for a in depth.keys():
  if depth[a] == m:
    found = a
    break

while depth[found] > 1:
  sons = [(depth[y], y) for x, y in links if x == found]
  sons.sort()
  print found, sons
  found = sons[-1][1]

