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

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

f = A("f")
n = B("n")
l = A("l")
i = B("i")
m = B("m")
b = A("b")
k = A("k")
d = B("d")
h = B("h")
g = B("g")

f.z = b
n.q = l
l.z = b
i.q = l
m.q = b
b.z = f
k.z = b
d.q = k
h.q = f
g.q = f
assert n.q.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

f = A("f")
n = B("n")
l = A("l")
i = B("i")
m = B("m")
b = A("b")
k = A("k")
d = B("d")
h = B("h")
g = B("g")

f.z = b
n.q = l
l.z = b
i.q = l
m.q = b
b.z = f
k.z = b
d.q = k
h.q = f
g.q = f
assert n.q.z.z.z.z.txt == "f"