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

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

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

n = A("n")
d = B("d")
j = C("j")

n.z = j
d.r = n
j.v = n
assert j.v.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

n = A("n")
d = B("d")
j = C("j")

n.z = j
d.r = n
j.v = n
assert j.v.z.v.txt == "n"