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

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

m = A("m")
j = B("j")
i = B("i")
h = A("h")
n = A("n")
l = A("l")
k = B("k")
f = B("f")

m.s = k
j.v = i
j.w = k
i.v = k
i.w = j
h.s = k
n.s = i
l.s = f
k.v = i
k.w = i
f.v = i
f.w = i
assert m.s.w.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

m = A("m")
j = B("j")
i = B("i")
h = A("h")
n = A("n")
l = A("l")
k = B("k")
f = B("f")

m.s = k
j.v = i
j.w = k
i.v = k
i.w = j
h.s = k
n.s = i
l.s = f
k.v = i
k.w = i
f.v = i
f.w = i
assert m.s.w.v.txt == "k"