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

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

b = A("b")
a = B("a")
m = A("m")

b.x = a
a.y = m
m.x = a
assert m.x.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

b = A("b")
a = B("a")
m = A("m")

b.x = a
a.y = m
m.x = a
assert m.x.y.x.txt == "a"