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

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

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

h = A("h")
m = B("m")
l = C("l")
f = B("f")
b = B("b")
d = C("d")

h.r = l
m.r = f
m.o = h
l.t = h
f.r = b
f.o = h
b.r = m
b.o = h
d.t = h
assert f.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

h = A("h")
m = B("m")
l = C("l")
f = B("f")
b = B("b")
d = C("d")

h.r = l
m.r = f
m.o = h
l.t = h
f.r = b
f.o = h
b.r = m
b.o = h
d.t = h
assert f.r.r.r.txt == "f"