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

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

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

f.w = c
h.u = c
m.w = b
b.w = f
a.u = c
l.w = c
n.u = f
c.w = b
assert m.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

f.w = c
h.u = c
m.w = b
b.w = f
a.u = c
l.w = c
n.u = f
c.w = b
assert m.w.w.w.txt == "c"