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

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

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

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

h = A("h")
j = B("j")
e = C("e")
n = D("n")

h.q = e
j.o = h
e.x = n
e.w = j
e.s = j
n.w = e
n.z = e
assert h.q.x.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

h = A("h")
j = B("j")
e = C("e")
n = D("n")

h.q = e
j.o = h
e.x = n
e.w = j
e.s = j
n.w = e
n.z = e
assert h.q.x.z.x.txt == "n"