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

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

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

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

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

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

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

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

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