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

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

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

g.z = l
b.r = l
b.q = i
l.z = m
f.r = g
f.q = k
i.r = g
i.q = b
k.r = l
k.q = f
m.z = l
assert m.z.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.r: A = None
        self.q: B = None
        self.txt = txt

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

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