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

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

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

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

i = A("i")
m = B("m")
e = C("e")
a = D("a")
l = C("l")

i.r = a
i.o = a
i.s = l
m.y = i
m.o = l
m.x = a
m.q = a
e.w = l
e.z = l
e.x = i
a.q = m
a.s = m
l.w = e
l.z = e
l.x = i
assert l.w.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.s: C = None
        self.o: D = None
        self.txt = txt

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

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

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

i = A("i")
m = B("m")
e = C("e")
a = D("a")
l = C("l")

i.r = a
i.o = a
i.s = l
m.y = i
m.o = l
m.x = a
m.q = a
e.w = l
e.z = l
e.x = i
a.q = m
a.s = m
l.w = e
l.z = e
l.x = i
assert l.w.x.s.txt == "l"