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

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

a = A("a")
d = B("d")
m = B("m")
j = A("j")

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

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

a = A("a")
d = B("d")
m = B("m")
j = A("j")

a.w = d
d.v = m
d.o = a
m.v = d
m.o = j
j.w = m
assert d.o.w.v.txt == "m"