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

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

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

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

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

g.o = l
g.w = l
g.z = e
e.w = g
e.r = a
l.y = a
d.s = e
m.s = e
a.y = l
assert d.s.w.z.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.w: C = None
        self.z: B = None
        self.txt = txt

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

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

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

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

g.o = l
g.w = l
g.z = e
e.w = g
e.r = a
l.y = a
d.s = e
m.s = e
a.y = l
assert d.s.w.z.r.y.txt == "l"