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

e = A("e")
f = B("f")
g = A("g")
n = B("n")

e.s = n
f.r = n
g.s = f
n.r = f
assert f.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

e = A("e")
f = B("f")
g = A("g")
n = B("n")

e.s = n
f.r = n
g.s = f
n.r = f
assert f.r.r.r.txt == "n"