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

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

l = A("l")
h = B("h")
g = B("g")
m = B("m")
e = B("e")
f = A("f")
c = B("c")
j = A("j")
n = B("n")
k = A("k")

l.y = g
l.q = m
h.z = e
g.z = h
m.z = e
e.z = m
f.y = h
f.q = e
c.z = m
j.y = g
j.q = h
n.z = c
k.y = g
k.q = h
assert e.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.txt = txt

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

l = A("l")
h = B("h")
g = B("g")
m = B("m")
e = B("e")
f = A("f")
c = B("c")
j = A("j")
n = B("n")
k = A("k")

l.y = g
l.q = m
h.z = e
g.z = h
m.z = e
e.z = m
f.y = h
f.q = e
c.z = m
j.y = g
j.q = h
n.z = c
k.y = g
k.q = h
assert e.z.z.z.z.z.txt == "m"