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

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

k = A("k")
f = B("f")
m = B("m")
c = B("c")
h = A("h")
e = B("e")
i = B("i")
d = B("d")
b = A("b")
g = A("g")

k.s = f
f.s = d
m.s = f
c.s = m
h.s = f
e.s = d
i.s = m
d.s = i
b.s = e
g.s = c
assert d.s.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

k = A("k")
f = B("f")
m = B("m")
c = B("c")
h = A("h")
e = B("e")
i = B("i")
d = B("d")
b = A("b")
g = A("g")

k.s = f
f.s = d
m.s = f
c.s = m
h.s = f
e.s = d
i.s = m
d.s = i
b.s = e
g.s = c
assert d.s.s.s.s.s.s.s.txt == "f"