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

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

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

h = A("h")
a = B("a")
c = C("c")
i = B("i")
k = A("k")
m = C("m")
g = B("g")

h.r = i
h.z = k
a.z = i
c.z = m
i.z = a
k.r = a
k.z = h
m.z = c
g.z = i
assert m.z.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.z: A = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
c = C("c")
i = B("i")
k = A("k")
m = C("m")
g = B("g")

h.r = i
h.z = k
a.z = i
c.z = m
i.z = a
k.r = a
k.z = h
m.z = c
g.z = i
assert m.z.z.z.z.z.z.z.txt == "c"