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

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

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

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

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

f.z = a
a.t = m
h.z = a
m.s = a
m.o = h
assert a.t.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

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

f.z = a
a.t = m
h.z = a
m.s = a
m.o = h
assert a.t.o.z.txt == "a"