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

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

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

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

n.v = g
n.r = g
n.p = g
m.s = g
g.x = n
g.w = n
g.s = m
a.v = g
a.r = g
a.p = g
assert a.v.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.r: C = None
        self.p: C = None
        self.txt = txt

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

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

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

n.v = g
n.r = g
n.p = g
m.s = g
g.x = n
g.w = n
g.s = m
a.v = g
a.r = g
a.p = g
assert a.v.w.p.txt == "g"