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

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

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

j = A("j")
h = B("h")
i = C("i")

j.z = i
h.u = j
h.r = j
i.u = h
assert i.u.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

j = A("j")
h = B("h")
i = C("i")

j.z = i
h.u = j
h.r = j
i.u = h
assert i.u.u.z.txt == "i"