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

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

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

a = A("a")
k = B("k")
h = C("h")
f = A("f")
i = B("i")

a.r = f
a.v = f
k.o = h
k.u = i
k.s = i
h.x = a
f.r = a
f.v = a
i.o = h
i.u = k
i.s = k
assert i.o.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.v: A = None
        self.txt = txt

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

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

a = A("a")
k = B("k")
h = C("h")
f = A("f")
i = B("i")

a.r = f
a.v = f
k.o = h
k.u = i
k.s = i
h.x = a
f.r = a
f.v = a
i.o = h
i.u = k
i.s = k
assert i.o.x.r.txt == "f"