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

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

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

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

d.w = m
d.o = j
d.p = k
j.q = m
m.w = k
k.q = m
n.w = m
n.o = j
n.p = k
assert k.q.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.o: B = None
        self.p: B = None
        self.txt = txt

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

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

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

d.w = m
d.o = j
d.p = k
j.q = m
m.w = k
k.q = m
n.w = m
n.o = j
n.p = k
assert k.q.w.q.txt == "m"