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

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

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

class D:
    def __init__(self, txt: str):
        self.w: E = None
        self.p: A = None
        self.txt = txt

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

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

l.w = d
a.u = d
a.s = e
g.s = e
e.w = d
e.p = l
d.o = e
d.x = e
assert l.w.x.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: E = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.w: E = None
        self.p: A = None
        self.txt = txt

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

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

l.w = d
a.u = d
a.s = e
g.s = e
e.w = d
e.p = l
d.o = e
d.x = e
assert l.w.x.p.w.txt == "d"