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

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

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

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

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

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

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