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

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

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

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

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

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

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

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

m.r = h
f.s = m
l.v = m
d.s = m
h.v = m
assert f.s.r.v.txt == "m"