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

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

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

n.x = i
l.s = n
l.x = f
f.s = n
f.x = a
a.s = n
a.x = f
i.x = n
m.s = i
m.x = a
c.s = i
c.x = f
assert l.x.s.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

n.x = i
l.s = n
l.x = f
f.s = n
f.x = a
a.s = n
a.x = f
i.x = n
m.s = i
m.x = a
c.s = i
c.x = f
assert l.x.s.x.x.x.x.x.txt == "i"