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

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

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

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

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

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

k.v = m
k.q = h
m.s = l
m.w = l
l.s = m
l.w = m
b.s = a
b.w = m
h.v = m
h.q = k
a.s = m
a.w = b
assert m.s.w.w.txt == "l"