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

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

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

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

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

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

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