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

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

k = A("k")
b = B("b")
a = A("a")
e = A("e")
m = B("m")
j = B("j")
i = B("i")
c = A("c")

k.q = m
b.z = e
a.q = b
e.q = b
m.z = c
j.z = e
i.z = c
c.q = m
assert i.z.q.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

k = A("k")
b = B("b")
a = A("a")
e = A("e")
m = B("m")
j = B("j")
i = B("i")
c = A("c")

k.q = m
b.z = e
a.q = b
e.q = b
m.z = c
j.z = e
i.z = c
c.q = m
assert i.z.q.z.q.txt == "m"