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

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

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

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

l = A("l")
e = B("e")
b = C("b")
h = D("h")

l.q = h
e.y = b
e.x = h
b.o = h
b.t = e
h.r = l
h.s = e
h.o = b
assert h.s.x.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

l = A("l")
e = B("e")
b = C("b")
h = D("h")

l.q = h
e.y = b
e.x = h
b.o = h
b.t = e
h.r = l
h.s = e
h.o = b
assert h.s.x.s.x.txt == "h"