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

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

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

m = A("m")
k = B("k")
i = C("i")
b = C("b")
h = B("h")
j = B("j")
g = C("g")

m.p = b
k.q = m
k.w = j
i.v = m
i.p = m
i.z = j
b.v = m
b.p = m
b.z = h
h.q = m
h.w = k
j.q = m
j.w = k
g.v = m
g.p = m
g.z = h
assert m.p.p.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

m = A("m")
k = B("k")
i = C("i")
b = C("b")
h = B("h")
j = B("j")
g = C("g")

m.p = b
k.q = m
k.w = j
i.v = m
i.p = m
i.z = j
b.v = m
b.p = m
b.z = h
h.q = m
h.w = k
j.q = m
j.w = k
g.v = m
g.p = m
g.z = h
assert m.p.p.p.v.txt == "m"