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

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

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

class D:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

a = A("a")
e = B("e")
h = C("h")
m = D("m")
g = B("g")
f = D("f")

a.o = h
e.y = h
e.t = h
h.y = m
m.z = h
g.y = h
g.t = h
f.z = h
assert m.z.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

a = A("a")
e = B("e")
h = C("h")
m = D("m")
g = B("g")
f = D("f")

a.o = h
e.y = h
e.t = h
h.y = m
m.z = h
g.y = h
g.t = h
f.z = h
assert m.z.y.z.txt == "h"