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

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

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

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

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

c.r = m
c.z = d
d.s = m
l.p = m
l.s = m
m.u = c
m.x = f
i.r = m
i.z = d
f.p = m
f.s = m
assert i.r.x.p.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.z: B = None
        self.txt = txt

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

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

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

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

c.r = m
c.z = d
d.s = m
l.p = m
l.s = m
m.u = c
m.x = f
i.r = m
i.z = d
f.p = m
f.s = m
assert i.r.x.p.x.p.txt == "m"