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

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

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

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

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

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

m.v = h
m.w = j
b.s = h
h.v = j
h.w = j
l.s = j
g.s = j
j.v = m
j.w = h
assert l.s.v.w.w.txt == "h"