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

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

b = A("b")
h = B("h")
a = A("a")
f = A("f")
m = A("m")
n = A("n")
l = B("l")
c = B("c")

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

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

b = A("b")
h = B("h")
a = A("a")
f = A("f")
m = A("m")
n = A("n")
l = B("l")
c = B("c")

b.q = l
b.z = h
h.q = a
a.q = l
a.z = c
f.q = c
f.z = l
m.q = c
m.z = c
n.q = l
n.z = l
l.q = m
c.q = f
assert a.z.q.q.q.q.q.z.q.txt == "m"