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

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

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

k = A("k")
f = B("f")
a = C("a")
h = B("h")
i = C("i")
l = C("l")
m = C("m")
g = B("g")
d = B("d")

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

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

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

k = A("k")
f = B("f")
a = C("a")
h = B("h")
i = C("i")
l = C("l")
m = C("m")
g = B("g")
d = B("d")

k.y = g
f.r = h
f.y = g
a.z = g
h.r = d
h.y = f
i.z = d
l.z = f
m.z = g
g.r = f
g.y = h
d.r = h
d.y = f
assert m.z.y.y.txt == "f"