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

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

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

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

n.y = j
n.v = g
n.r = g
j.v = c
j.p = n
c.s = j
c.y = g
c.w = g
g.v = c
g.p = n
assert j.v.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.v: B = None
        self.r: B = None
        self.txt = txt

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

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

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

n.y = j
n.v = g
n.r = g
j.v = c
j.p = n
c.s = j
c.y = g
c.w = g
g.v = c
g.p = n
assert j.v.y.p.txt == "n"