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

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

e = A("e")
n = B("n")
m = B("m")
k = B("k")

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

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

e = A("e")
n = B("n")
m = B("m")
k = B("k")

e.o = m
n.q = m
m.q = n
k.q = n
assert k.q.q.q.txt == "n"