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

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

b.o = a
a.x = n
n.o = a
assert a.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

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

b.o = a
a.x = n
n.o = a
assert a.x.o.x.txt == "n"