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

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

c = A("c")
l = B("l")
f = A("f")
j = B("j")
b = A("b")
h = A("h")
m = B("m")
k = A("k")

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

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

c = A("c")
l = B("l")
f = A("f")
j = B("j")
b = A("b")
h = A("h")
m = B("m")
k = A("k")

c.r = m
c.v = k
l.o = c
l.w = f
f.r = l
f.v = b
j.o = k
j.w = f
b.r = l
b.v = c
h.r = j
h.v = b
m.o = h
m.w = h
k.r = j
k.v = h
assert h.v.r.w.r.txt == "l"