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

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

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

a.x = h
a.o = n
n.o = a
h.x = a
h.o = n
assert a.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.o: B = None
        self.txt = txt

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

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

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