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

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

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

class D:
    def __init__(self, txt: str):
        self.z: E = None
        self.w: A = None
        self.q: A = None
        self.t: E = None
        self.v: B = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

m = A("m")
f = B("f")
c = C("c")
e = D("e")
d = E("d")

m.p = e
m.x = c
f.r = m
c.z = m
c.t = m
e.z = d
e.t = d
e.w = m
e.q = m
e.v = f
d.x = c
assert m.x.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.x: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.z: E = None
        self.w: A = None
        self.q: A = None
        self.t: E = None
        self.v: B = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

m = A("m")
f = B("f")
c = C("c")
e = D("e")
d = E("d")

m.p = e
m.x = c
f.r = m
c.z = m
c.t = m
e.z = d
e.t = d
e.w = m
e.q = m
e.v = f
d.x = c
assert m.x.z.x.txt == "c"