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

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

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

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

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

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

b.x = h
n.t = h
n.s = b
h.t = n
h.s = b
assert b.x.s.x.txt == "h"