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

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

m = A("m")
e = B("e")
k = A("k")
d = B("d")
i = B("i")
c = B("c")

m.q = d
e.s = c
k.q = e
d.s = i
i.s = c
c.s = i
assert d.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

m = A("m")
e = B("e")
k = A("k")
d = B("d")
i = B("i")
c = B("c")

m.q = d
e.s = c
k.q = e
d.s = i
i.s = c
c.s = i
assert d.s.s.s.s.s.s.txt == "c"