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

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

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

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

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

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

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