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

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

m = A("m")
n = B("n")
i = A("i")
j = B("j")
a = A("a")
h = B("h")
k = B("k")

m.q = i
m.o = h
n.q = j
i.q = m
i.o = h
j.q = h
a.q = i
a.o = h
h.q = n
k.q = n
assert n.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.o: B = None
        self.txt = txt

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

m = A("m")
n = B("n")
i = A("i")
j = B("j")
a = A("a")
h = B("h")
k = B("k")

m.q = i
m.o = h
n.q = j
i.q = m
i.o = h
j.q = h
a.q = i
a.o = h
h.q = n
k.q = n
assert n.q.q.q.q.q.q.txt == "n"