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

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

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

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

b.z = i
i.u = b
i.x = f
f.r = b
h.u = b
h.x = f
assert i.x.r.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

b.z = i
i.u = b
i.x = f
f.r = b
h.u = b
h.x = f
assert i.x.r.z.u.txt == "b"