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

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

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

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

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

e.w = d
m.s = g
m.t = e
d.s = e
g.w = d
a.s = e
i.s = g
i.t = e
l.s = g
l.t = e
assert d.s.w.s.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

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

e.w = d
m.s = g
m.t = e
d.s = e
g.w = d
a.s = e
i.s = g
i.t = e
l.s = g
l.t = e
assert d.s.w.s.w.s.txt == "e"