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

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

n = A("n")
l = B("l")
m = B("m")
e = A("e")
i = B("i")
f = B("f")
b = B("b")
k = A("k")

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

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

n = A("n")
l = B("l")
m = B("m")
e = A("e")
i = B("i")
f = B("f")
b = B("b")
k = A("k")

n.r = i
n.z = e
l.q = f
m.q = i
e.r = m
e.z = k
i.q = l
f.q = b
b.q = i
k.r = l
k.z = e
assert m.q.q.q.txt == "f"