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

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

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

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

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

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

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

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

g.z = n
g.p = k
k.r = a
a.p = n
n.z = g
n.p = k
assert k.r.p.p.txt == "k"