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

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

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

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

h.w = n
a.u = k
a.o = k
n.v = k
n.r = k
n.o = h
k.u = a
k.o = a
assert n.o.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

h.w = n
a.u = k
a.o = k
n.v = k
n.r = k
n.o = h
k.u = a
k.o = a
assert n.o.w.o.txt == "h"