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

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

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

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

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

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

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

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

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