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

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

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

a = A("a")
i = B("i")
m = C("m")
j = C("j")

a.w = j
i.z = a
i.w = m
m.s = a
j.s = a
assert i.z.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

a = A("a")
i = B("i")
m = C("m")
j = C("j")

a.w = j
i.z = a
i.w = m
m.s = a
j.s = a
assert i.z.w.s.w.txt == "j"