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

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

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

i.u = e
e.y = i
m.y = i
assert m.y.u.y.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

i.u = e
e.y = i
m.y = i
assert m.y.u.y.txt == "i"