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

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

e = A("e")
c = B("c")
g = B("g")

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

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

e = A("e")
c = B("c")
g = B("g")

e.w = c
c.y = e
g.y = e
assert c.y.w.y.txt == "e"