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

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

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

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

class E:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

m = A("m")
i = B("i")
b = C("b")
j = D("j")
g = E("g")

m.w = g
m.z = i
i.w = j
b.p = j
b.v = j
j.y = m
g.s = m
assert m.w.s.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: E = None
        self.z: B = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

m = A("m")
i = B("i")
b = C("b")
j = D("j")
g = E("g")

m.w = g
m.z = i
i.w = j
b.p = j
b.v = j
j.y = m
g.s = m
assert m.w.s.w.s.txt == "m"