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

class B:
    def __init__(self, txt: str):
        self.v: C = None
        self.q: B = None
        self.o: B = None
        self.txt = txt

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

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

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

class B:
    def __init__(self, txt: str):
        self.v: C = None
        self.q: B = None
        self.o: B = None
        self.txt = txt

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

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

h.r = d
m.v = d
m.q = l
m.o = l
d.r = m
d.z = i
l.v = i
l.q = m
l.o = m
f.r = i
i.r = m
i.z = d
assert h.r.z.r.txt == "m"