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.z: C = None
        self.txt = txt

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

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

n.x = k
n.v = h
k.z = h
h.r = n
h.s = n
h.x = n
assert n.x.z.x.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.z: C = None
        self.txt = txt

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

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

n.x = k
n.v = h
k.z = h
h.r = n
h.s = n
h.x = n
assert n.x.z.x.txt == "n"