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

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

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

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

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

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

e.o = n
i.q = n
i.w = e
n.o = e
m.o = n
f.q = e
f.w = m
assert n.o.o.o.txt == "e"