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

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

i = A("i")
d = B("d")
a = A("a")
l = A("l")
h = B("h")
m = A("m")

i.q = m
d.o = l
a.q = i
l.q = m
h.o = a
m.q = a
assert m.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.o: A = None
        self.txt = txt

i = A("i")
d = B("d")
a = A("a")
l = A("l")
h = B("h")
m = A("m")

i.q = m
d.o = l
a.q = i
l.q = m
h.o = a
m.q = a
assert m.q.q.q.q.q.q.txt == "m"