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

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

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

a = A("a")
d = B("d")
k = C("k")
h = A("h")

a.x = h
a.s = d
d.o = k
k.z = d
k.y = d
k.v = d
h.x = a
h.s = d
assert d.o.v.o.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.s: B = None
        self.txt = txt

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

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

a = A("a")
d = B("d")
k = C("k")
h = A("h")

a.x = h
a.s = d
d.o = k
k.z = d
k.y = d
k.v = d
h.x = a
h.s = d
assert d.o.v.o.v.txt == "d"