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

i = A("i")
f = B("f")
a = B("a")
l = B("l")
b = B("b")
g = B("g")
e = A("e")

i.s = b
f.r = b
a.r = l
l.r = g
b.r = l
g.r = f
e.s = b
assert g.r.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

i = A("i")
f = B("f")
a = B("a")
l = B("l")
b = B("b")
g = B("g")
e = A("e")

i.s = b
f.r = b
a.r = l
l.r = g
b.r = l
g.r = f
e.s = b
assert g.r.r.r.r.r.r.r.txt == "l"