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

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

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

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

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

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

g.u = f
d.o = g
d.w = f
f.o = g
f.w = d
assert g.u.o.u.txt == "f"