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

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

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

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

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

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

g.w = d
d.u = g
a.w = d
assert a.w.u.w.txt == "d"