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

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

i.z = a
a.q = m
h.z = a
f.z = a
g.z = a
b.z = a
m.z = a
assert i.z.q.z.q.z.q.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

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

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