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

e = A("e")
d = B("d")
g = A("g")
a = A("a")
b = A("b")

e.y = d
d.w = b
g.y = d
a.y = d
b.y = d
assert e.y.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

e = A("e")
d = B("d")
g = A("g")
a = A("a")
b = A("b")

e.y = d
d.w = b
g.y = d
a.y = d
b.y = d
assert e.y.w.y.w.txt == "b"