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

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

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

h = A("h")
k = B("k")
m = C("m")
c = C("c")
n = A("n")
d = C("d")

h.o = n
k.w = m
k.v = h
m.z = h
m.u = h
m.s = k
c.z = n
c.u = n
c.s = k
n.o = h
d.z = n
d.s = k
d.u = h
assert m.s.v.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

h = A("h")
k = B("k")
m = C("m")
c = C("c")
n = A("n")
d = C("d")

h.o = n
k.w = m
k.v = h
m.z = h
m.u = h
m.s = k
c.z = n
c.u = n
c.s = k
n.o = h
d.z = n
d.s = k
d.u = h
assert m.s.v.o.txt == "n"