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

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

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

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

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

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

l.y = i
b.q = m
b.s = g
g.y = c
d.q = b
d.s = i
c.y = i
e.q = n
e.s = g
i.y = c
m.q = n
m.s = g
n.q = m
n.s = g
assert b.q.q.q.q.q.q.q.q.q.txt == "m"