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

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

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

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

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

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

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

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

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