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

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

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

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

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

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

m.o = g
m.v = g
f.w = g
g.w = f
assert m.o.w.w.txt == "g"