class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.y: B = 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: B = None
        self.txt = txt

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

l.t = m
l.y = a
g.z = a
h.z = a
a.z = g
b.z = a
f.t = h
f.y = a
m.z = a
assert b.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.y: B = 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: B = None
        self.txt = txt

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

l.t = m
l.y = a
g.z = a
h.z = a
a.z = g
b.z = a
f.t = h
f.y = a
m.z = a
assert b.z.z.z.txt == "a"