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

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

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

class D:
    def __init__(self, txt: str):
        self.s: A = None
        self.x: B = None
        self.u: A = None
        self.v: B = None
        self.txt = txt

m = A("m")
d = B("d")
l = C("l")
i = D("i")

m.p = i
m.s = i
m.z = l
d.z = i
d.o = l
l.r = d
l.q = d
l.u = d
i.s = m
i.u = m
i.x = d
i.v = d
assert m.p.x.o.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.z: C = None
        self.s: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.s: A = None
        self.x: B = None
        self.u: A = None
        self.v: B = None
        self.txt = txt

m = A("m")
d = B("d")
l = C("l")
i = D("i")

m.p = i
m.s = i
m.z = l
d.z = i
d.o = l
l.r = d
l.q = d
l.u = d
i.s = m
i.u = m
i.x = d
i.v = d
assert m.p.x.o.u.txt == "d"