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

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

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

k = A("k")
f = B("f")
n = C("n")

k.x = f
k.v = n
f.r = n
f.s = n
f.w = k
n.v = k
assert n.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.v: C = None
        self.txt = txt

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

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

k = A("k")
f = B("f")
n = C("n")

k.x = f
k.v = n
f.r = n
f.s = n
f.w = k
n.v = k
assert n.v.v.v.txt == "k"