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

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

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

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

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

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

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