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.txt = txt

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

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

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

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