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

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

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

e.r = i
b.r = i
m.r = e
i.r = e
assert m.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

e.r = i
b.r = i
m.r = e
i.r = e
assert m.r.r.r.txt == "e"