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

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

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

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

l.y = h
e.x = n
e.o = m
n.y = m
n.q = m
d.x = n
d.o = m
f.y = m
f.q = a
h.y = a
h.q = a
m.y = h
a.y = n
assert m.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

l.y = h
e.x = n
e.o = m
n.y = m
n.q = m
d.x = n
d.o = m
f.y = m
f.q = a
h.y = a
h.q = a
m.y = h
a.y = n
assert m.y.y.y.txt == "n"