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

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

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

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

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

c = A("c")
a = B("a")
e = C("e")
h = D("h")
b = E("b")

c.q = h
a.u = e
a.w = h
e.u = h
e.y = c
h.r = b
h.t = c
b.p = h
b.q = h
b.s = a
b.w = e
assert e.u.r.s.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

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

c = A("c")
a = B("a")
e = C("e")
h = D("h")
b = E("b")

c.q = h
a.u = e
a.w = h
e.u = h
e.y = c
h.r = b
h.t = c
b.p = h
b.q = h
b.s = a
b.w = e
assert e.u.r.s.w.r.txt == "b"