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

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

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

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

c = A("c")
g = B("g")
l = C("l")
a = D("a")
f = B("f")

c.y = a
c.s = l
g.w = f
l.w = a
a.z = l
a.w = l
a.o = c
a.p = g
f.w = g
assert g.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.s: C = None
        self.txt = txt

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

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

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

c = A("c")
g = B("g")
l = C("l")
a = D("a")
f = B("f")

c.y = a
c.s = l
g.w = f
l.w = a
a.z = l
a.w = l
a.o = c
a.p = g
f.w = g
assert g.w.w.w.w.w.txt == "f"