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

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

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

g = A("g")
c = B("c")
k = C("k")
h = A("h")

g.s = c
c.y = k
c.r = k
c.p = g
k.z = c
h.s = c
assert k.z.p.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

g = A("g")
c = B("c")
k = C("k")
h = A("h")

g.s = c
c.y = k
c.r = k
c.p = g
k.z = c
h.s = c
assert k.z.p.s.p.txt == "g"