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

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

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

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

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

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

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

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

h.x = k
h.w = e
e.s = h
e.z = h
e.r = k
k.o = e
k.v = e
assert e.r.v.z.txt == "h"