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

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

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

a = A("a")
f = B("f")
n = C("n")
g = B("g")

a.p = n
a.r = n
a.t = f
f.v = a
f.z = g
f.x = g
n.s = g
n.x = f
n.q = a
g.v = a
g.z = f
g.x = f
assert n.q.p.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.t: B = None
        self.r: C = None
        self.txt = txt

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

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

a = A("a")
f = B("f")
n = C("n")
g = B("g")

a.p = n
a.r = n
a.t = f
f.v = a
f.z = g
f.x = g
n.s = g
n.x = f
n.q = a
g.v = a
g.z = f
g.x = f
assert n.q.p.x.v.txt == "a"