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

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

m = A("m")
f = B("f")
d = A("d")
g = B("g")
c = B("c")
b = B("b")

m.w = d
m.u = d
f.s = d
d.w = m
d.u = m
g.s = m
c.s = m
b.s = d
assert f.s.u.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.u: A = None
        self.txt = txt

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

m = A("m")
f = B("f")
d = A("d")
g = B("g")
c = B("c")
b = B("b")

m.w = d
m.u = d
f.s = d
d.w = m
d.u = m
g.s = m
c.s = m
b.s = d
assert f.s.u.w.w.w.w.txt == "m"