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

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

d = A("d")
b = B("b")
h = A("h")
c = B("c")
l = A("l")
m = A("m")

d.w = b
d.o = h
b.v = h
h.w = b
h.o = l
c.v = m
l.w = c
l.o = h
m.w = b
m.o = l
assert h.o.w.v.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.o: A = None
        self.txt = txt

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

d = A("d")
b = B("b")
h = A("h")
c = B("c")
l = A("l")
m = A("m")

d.w = b
d.o = h
b.v = h
h.w = b
h.o = l
c.v = m
l.w = c
l.o = h
m.w = b
m.o = l
assert h.o.w.v.o.w.txt == "c"