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

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

n = A("n")
m = B("m")
k = A("k")

n.o = k
m.x = k
k.o = n
assert m.x.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

n = A("n")
m = B("m")
k = A("k")

n.o = k
m.x = k
k.o = n
assert m.x.o.o.txt == "k"