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

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

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

l = A("l")
f = B("f")
i = C("i")

l.r = i
f.v = i
i.s = f
i.p = f
i.x = l
assert i.s.v.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

l = A("l")
f = B("f")
i = C("i")

l.r = i
f.v = i
i.s = f
i.p = f
i.x = l
assert i.s.v.x.txt == "l"