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.q: A = None
        self.txt = txt

n = A("n")
e = B("e")
m = B("m")
b = A("b")
l = A("l")
g = B("g")
h = A("h")
f = A("f")

n.q = e
e.z = h
e.q = l
m.z = l
m.q = h
b.q = m
l.q = m
g.z = n
g.q = l
h.q = g
f.q = e
assert m.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.q: A = None
        self.txt = txt

n = A("n")
e = B("e")
m = B("m")
b = A("b")
l = A("l")
g = B("g")
h = A("h")
f = A("f")

n.q = e
e.z = h
e.q = l
m.z = l
m.q = h
b.q = m
l.q = m
g.z = n
g.q = l
h.q = g
f.q = e
assert m.z.q.z.q.txt == "m"