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

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

h = A("h")
g = B("g")
e = A("e")
a = B("a")

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

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

h = A("h")
g = B("g")
e = A("e")
a = B("a")

h.y = a
g.w = e
e.y = g
a.w = h
assert g.w.y.w.txt == "e"