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

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

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

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

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

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

h.x = c
c.q = b
e.z = i
i.v = h
b.r = e
b.x = h
assert b.x.x.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

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

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

h.x = c
c.q = b
e.z = i
i.v = h
b.r = e
b.x = h
assert b.x.x.q.x.txt == "h"