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

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

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

f.r = j
k.w = j
k.s = f
j.r = f
assert j.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

f.r = j
k.w = j
k.s = f
j.r = f
assert j.r.r.r.txt == "f"