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

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

a = A("a")
f = B("f")
j = B("j")

a.s = j
f.o = j
f.r = j
j.o = f
j.r = f
assert j.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.o: B = None
        self.r: B = None
        self.txt = txt

a = A("a")
f = B("f")
j = B("j")

a.s = j
f.o = j
f.r = j
j.o = f
j.r = f
assert j.r.r.r.txt == "f"