class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.u: A = None
        self.o: A = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.x: B = None
        self.o: C = None
        self.txt = txt

b = A("b")
e = B("e")
m = C("m")
a = C("a")
f = A("f")
h = C("h")
l = C("l")
n = A("n")
g = C("g")

b.p = f
e.y = m
e.u = b
e.o = b
m.x = e
m.o = g
a.x = e
a.o = m
f.p = b
h.x = e
h.o = l
l.x = e
l.o = g
n.p = f
g.x = e
g.o = a
assert n.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.u: A = None
        self.o: A = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.x: B = None
        self.o: C = None
        self.txt = txt

b = A("b")
e = B("e")
m = C("m")
a = C("a")
f = A("f")
h = C("h")
l = C("l")
n = A("n")
g = C("g")

b.p = f
e.y = m
e.u = b
e.o = b
m.x = e
m.o = g
a.x = e
a.o = m
f.p = b
h.x = e
h.o = l
l.x = e
l.o = g
n.p = f
g.x = e
g.o = a
assert n.p.p.p.p.p.txt == "f"