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

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

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

c.o = m
i.x = c
m.x = c
assert i.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

c.o = m
i.x = c
m.x = c
assert i.x.o.x.txt == "c"