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

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

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

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

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

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

h.y = a
d.x = a
d.w = h
a.x = d
a.w = h
assert d.x.w.y.txt == "a"