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

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

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

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

a.u = g
n.p = g
n.s = a
g.z = n
g.r = a
assert a.u.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

a.u = g
n.p = g
n.s = a
g.z = n
g.r = a
assert a.u.r.u.txt == "g"