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

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

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

m = A("m")
c = B("c")
d = C("d")
a = B("a")

m.p = d
m.o = d
m.q = a
c.z = a
d.v = m
a.z = c
assert a.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.o: C = None
        self.q: B = None
        self.txt = txt

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

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

m = A("m")
c = B("c")
d = C("d")
a = B("a")

m.p = d
m.o = d
m.q = a
c.z = a
d.v = m
a.z = c
assert a.z.z.z.txt == "c"