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

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

a = A("a")
b = B("b")
h = B("h")
g = A("g")
l = A("l")
m = A("m")

a.w = b
a.r = b
b.w = m
b.v = h
h.w = m
h.v = b
g.w = b
g.r = b
l.w = b
l.r = b
m.w = h
m.r = h
assert m.r.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.r: B = None
        self.txt = txt

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

a = A("a")
b = B("b")
h = B("h")
g = A("g")
l = A("l")
m = A("m")

a.w = b
a.r = b
b.w = m
b.v = h
h.w = m
h.v = b
g.w = b
g.r = b
l.w = b
l.r = b
m.w = h
m.r = h
assert m.r.v.v.v.txt == "b"