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

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

a = A("a")
l = B("l")
m = A("m")
d = A("d")
f = B("f")
h = A("h")

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

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

a = A("a")
l = B("l")
m = A("m")
d = A("d")
f = B("f")
h = A("h")

a.w = l
a.v = h
l.o = d
m.w = f
m.v = h
d.w = l
d.v = h
f.o = m
h.w = f
h.v = m
assert f.o.v.w.o.v.txt == "h"