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

b = A("b")
c = B("c")
a = B("a")
d = A("d")
e = A("e")
m = B("m")
k = B("k")
l = B("l")
g = A("g")

b.r = c
b.z = d
c.q = k
a.q = m
d.r = k
d.z = e
e.r = l
e.z = b
m.q = l
k.q = a
l.q = m
g.r = a
g.z = d
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

b = A("b")
c = B("c")
a = B("a")
d = A("d")
e = A("e")
m = B("m")
k = B("k")
l = B("l")
g = A("g")

b.r = c
b.z = d
c.q = k
a.q = m
d.r = k
d.z = e
e.r = l
e.z = b
m.q = l
k.q = a
l.q = m
g.r = a
g.z = d
assert m.q.q.q.txt == "l"