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

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

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

j = A("j")
l = B("l")
k = C("k")
g = A("g")
i = B("i")
d = C("d")

j.w = l
l.z = g
l.y = i
l.s = i
k.p = j
k.y = d
g.w = i
i.z = g
i.y = l
i.s = l
d.p = j
d.y = k
assert l.z.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

j = A("j")
l = B("l")
k = C("k")
g = A("g")
i = B("i")
d = C("d")

j.w = l
l.z = g
l.y = i
l.s = i
k.p = j
k.y = d
g.w = i
i.z = g
i.y = l
i.s = l
d.p = j
d.y = k
assert l.z.w.z.txt == "g"