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

i = A("i")
e = B("e")
m = B("m")

i.o = m
e.q = m
m.q = e
assert i.o.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

i = A("i")
e = B("e")
m = B("m")

i.o = m
e.q = m
m.q = e
assert i.o.q.q.txt == "m"