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

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

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

g = A("g")
e = B("e")
h = C("h")
j = A("j")
f = A("f")
l = C("l")
m = B("m")
b = C("b")

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

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

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

g = A("g")
e = B("e")
h = C("h")
j = A("j")
f = A("f")
l = C("l")
m = B("m")
b = C("b")

g.z = f
e.x = h
e.u = m
e.z = j
h.u = e
h.r = e
j.z = f
f.z = j
l.u = m
l.r = m
m.x = h
m.u = e
m.z = g
b.u = m
b.r = m
assert g.z.z.z.z.z.z.txt == "j"