class A:
    def __init__(self, txt: str):
        self.r: 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.p: A = None
        self.y: B = None
        self.u: B = None
        self.txt = txt

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

g.r = n
h.s = n
n.p = g
n.y = h
n.u = h
assert h.s.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: 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.p: A = None
        self.y: B = None
        self.u: B = None
        self.txt = txt

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

g.r = n
h.s = n
n.p = g
n.y = h
n.u = h
assert h.s.p.r.txt == "n"