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

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

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

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

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

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

h.x = e
i.x = e
i.s = h
e.x = i
e.s = h
b.x = i
assert i.s.x.x.txt == "i"