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

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

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

n = A("n")
m = B("m")
k = C("k")
j = A("j")
g = C("g")

n.o = j
m.z = n
m.r = n
m.p = n
k.s = g
k.w = m
k.y = n
j.o = n
g.s = k
g.w = m
g.y = n
assert g.w.z.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

n = A("n")
m = B("m")
k = C("k")
j = A("j")
g = C("g")

n.o = j
m.z = n
m.r = n
m.p = n
k.s = g
k.w = m
k.y = n
j.o = n
g.s = k
g.w = m
g.y = n
assert g.w.z.o.o.txt == "n"