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

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

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

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

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

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

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

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

m.q = h
m.v = h
n.s = m
h.u = m
h.s = m
h.o = m
d.s = m
assert d.s.q.s.txt == "m"