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

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

h = A("h")
e = B("e")
b = A("b")

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

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

h = A("h")
e = B("e")
b = A("b")

h.x = e
h.v = b
e.o = b
b.x = e
b.v = h
assert h.x.o.x.txt == "e"