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

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

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

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

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

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

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