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

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

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

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

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

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

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