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

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

n = A("n")
b = B("b")
i = B("i")
g = A("g")
d = A("d")
l = A("l")
c = B("c")
m = A("m")

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

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

n = A("n")
b = B("b")
i = B("i")
g = A("g")
d = A("d")
l = A("l")
c = B("c")
m = A("m")

n.q = m
b.x = c
b.z = i
i.x = c
i.z = b
g.q = n
d.q = g
l.q = g
c.x = b
c.z = b
m.q = l
assert n.q.q.q.q.q.q.txt == "l"