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

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

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

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

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

m.z = d
d.z = a
d.u = a
a.v = d
f.v = d
f.s = d
f.p = a
assert m.z.z.v.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

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

m.z = d
d.z = a
d.u = a
a.v = d
f.v = d
f.s = d
f.p = a
assert m.z.z.v.z.txt == "a"