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

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

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

h = A("h")
f = B("f")
l = C("l")
c = A("c")
i = C("i")
g = B("g")
b = B("b")
a = A("a")
m = A("m")

h.r = i
f.u = i
l.u = m
l.z = f
c.r = i
i.u = m
i.z = b
g.u = i
b.u = l
a.r = l
m.r = i
assert g.u.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

h = A("h")
f = B("f")
l = C("l")
c = A("c")
i = C("i")
g = B("g")
b = B("b")
a = A("a")
m = A("m")

h.r = i
f.u = i
l.u = m
l.z = f
c.r = i
i.u = m
i.z = b
g.u = i
b.u = l
a.r = l
m.r = i
assert g.u.z.u.txt == "l"