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

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

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

g = A("g")
c = B("c")
j = C("j")
e = C("e")
n = C("n")

g.z = j
c.q = e
c.v = n
j.z = g
j.p = g
j.r = g
e.z = g
e.p = g
e.r = g
n.z = g
n.p = g
n.r = g
assert c.v.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

g = A("g")
c = B("c")
j = C("j")
e = C("e")
n = C("n")

g.z = j
c.q = e
c.v = n
j.z = g
j.p = g
j.r = g
e.z = g
e.p = g
e.r = g
n.z = g
n.p = g
n.r = g
assert c.v.z.z.z.txt == "g"