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

class B:
    def __init__(self, txt: str):
        self.p: E = None
        self.txt = txt

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

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

class E:
    def __init__(self, txt: str):
        self.u: B = None
        self.x: A = None
        self.w: D = None
        self.p: D = None
        self.q: A = None
        self.txt = txt

m = A("m")
g = B("g")
b = C("b")
a = D("a")
d = E("d")

m.z = g
m.r = b
m.t = b
g.p = d
b.z = m
a.w = m
d.u = g
d.x = m
d.q = m
d.w = a
d.p = a
assert d.w.w.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.r: C = None
        self.t: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: E = None
        self.txt = txt

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

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

class E:
    def __init__(self, txt: str):
        self.u: B = None
        self.x: A = None
        self.w: D = None
        self.p: D = None
        self.q: A = None
        self.txt = txt

m = A("m")
g = B("g")
b = C("b")
a = D("a")
d = E("d")

m.z = g
m.r = b
m.t = b
g.p = d
b.z = m
a.w = m
d.u = g
d.x = m
d.q = m
d.w = a
d.p = a
assert d.w.w.z.p.txt == "d"