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

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

f = A("f")
b = B("b")
m = A("m")
k = B("k")
g = A("g")
n = A("n")

f.s = g
b.w = n
b.o = n
m.s = f
k.w = g
k.o = n
g.s = m
n.s = g
assert k.w.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

f = A("f")
b = B("b")
m = A("m")
k = B("k")
g = A("g")
n = A("n")

f.s = g
b.w = n
b.o = n
m.s = f
k.w = g
k.o = n
g.s = m
n.s = g
assert k.w.s.s.s.s.txt == "m"