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

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

h = A("h")
k = B("k")
j = A("j")
g = A("g")
a = A("a")
m = B("m")
l = A("l")

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

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

h = A("h")
k = B("k")
j = A("j")
g = A("g")
a = A("a")
m = B("m")
l = A("l")

h.z = k
k.q = a
j.z = m
g.z = m
a.z = k
m.q = l
l.z = m
assert l.z.q.z.q.z.txt == "m"