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

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

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

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

m = A("m")
i = B("i")
f = C("f")
g = D("g")
b = B("b")

m.z = g
i.t = f
f.w = m
f.s = m
f.z = m
f.r = i
g.t = f
g.y = m
g.z = i
b.t = f
assert m.z.z.t.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

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

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

m = A("m")
i = B("i")
f = C("f")
g = D("g")
b = B("b")

m.z = g
i.t = f
f.w = m
f.s = m
f.z = m
f.r = i
g.t = f
g.y = m
g.z = i
b.t = f
assert m.z.z.t.z.z.txt == "g"