class A:
    def __init__(self, txt: str):
        self.r: B = 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.r: A = None
        self.txt = txt

f = A("f")
m = B("m")
k = C("k")
b = B("b")
h = A("h")

f.r = m
m.z = k
k.r = f
b.z = k
h.r = b
assert f.r.z.r.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = 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.r: A = None
        self.txt = txt

f = A("f")
m = B("m")
k = C("k")
b = B("b")
h = A("h")

f.r = m
m.z = k
k.r = f
b.z = k
h.r = b
assert f.r.z.r.r.z.txt == "k"