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

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

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

n = A("n")
m = B("m")
h = C("h")
f = C("f")
g = B("g")
d = C("d")

n.v = f
m.q = n
h.q = n
h.o = n
h.v = n
f.q = n
f.o = n
f.v = n
g.q = n
d.q = n
d.o = n
d.v = n
assert h.v.v.q.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

n = A("n")
m = B("m")
h = C("h")
f = C("f")
g = B("g")
d = C("d")

n.v = f
m.q = n
h.q = n
h.o = n
h.v = n
f.q = n
f.o = n
f.v = n
g.q = n
d.q = n
d.o = n
d.v = n
assert h.v.v.q.v.v.v.txt == "f"