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

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

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

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

n = A("n")
l = B("l")
e = C("e")
i = D("i")
d = D("d")
f = C("f")

n.x = l
l.y = d
l.s = f
e.z = i
e.q = f
i.x = e
i.o = e
d.x = e
d.o = f
f.z = d
f.q = e
assert d.x.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

n = A("n")
l = B("l")
e = C("e")
i = D("i")
d = D("d")
f = C("f")

n.x = l
l.y = d
l.s = f
e.z = i
e.q = f
i.x = e
i.o = e
d.x = e
d.o = f
f.z = d
f.q = e
assert d.x.q.q.q.txt == "f"