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

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

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

i = A("i")
d = B("d")
c = C("c")
n = A("n")
k = C("k")

i.r = d
i.z = c
d.q = n
c.q = k
c.u = k
c.p = i
n.r = d
n.z = k
k.q = c
k.u = c
k.p = n
assert c.p.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.z: C = None
        self.txt = txt

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

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

i = A("i")
d = B("d")
c = C("c")
n = A("n")
k = C("k")

i.r = d
i.z = c
d.q = n
c.q = k
c.u = k
c.p = i
n.r = d
n.z = k
k.q = c
k.u = c
k.p = n
assert c.p.r.q.txt == "n"