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

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

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

h = A("h")
a = B("a")
i = C("i")
f = C("f")

h.u = i
a.x = f
a.w = h
i.w = f
i.z = h
f.w = i
f.z = h
assert h.u.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
i = C("i")
f = C("f")

h.u = i
a.x = f
a.w = h
i.w = f
i.z = h
f.w = i
f.z = h
assert h.u.z.u.txt == "i"