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

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

l = A("l")
h = B("h")
n = B("n")
m = A("m")
f = A("f")
i = A("i")

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

l = A("l")
h = B("h")
n = B("n")
m = A("m")
f = A("f")
i = A("i")

l.z = h
h.z = n
h.q = l
n.z = h
n.q = m
m.z = n
f.z = n
i.z = n
assert f.z.z.q.z.q.z.txt == "h"