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

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

f = A("f")
i = B("i")
d = B("d")
e = A("e")
m = B("m")
l = B("l")
b = A("b")
j = A("j")

f.s = l
i.u = l
i.s = m
d.u = i
d.s = i
e.s = m
m.u = l
m.s = d
l.u = d
l.s = i
b.s = d
j.s = l
assert f.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.u: B = None
        self.s: B = None
        self.txt = txt

f = A("f")
i = B("i")
d = B("d")
e = A("e")
m = B("m")
l = B("l")
b = A("b")
j = A("j")

f.s = l
i.u = l
i.s = m
d.u = i
d.s = i
e.s = m
m.u = l
m.s = d
l.u = d
l.s = i
b.s = d
j.s = l
assert f.s.s.s.txt == "m"