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

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

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

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

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

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

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

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

d.z = h
i.z = h
h.w = i
h.v = d
j.w = i
j.v = d
assert i.z.v.z.txt == "h"