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

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

l = A("l")
j = B("j")
a = A("a")
n = A("n")
e = B("e")

l.s = a
j.q = n
j.o = a
a.s = n
n.s = a
e.q = a
e.o = l
assert a.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

l = A("l")
j = B("j")
a = A("a")
n = A("n")
e = B("e")

l.s = a
j.q = n
j.o = a
a.s = n
n.s = a
e.q = a
e.o = l
assert a.s.s.s.txt == "n"