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

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

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

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

class E:
    def __init__(self, txt: str):
        self.s: C = None
        self.x: D = None
        self.z: C = None
        self.txt = txt

c = A("c")
k = B("k")
a = C("a")
i = D("i")
g = E("g")

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

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

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

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

class E:
    def __init__(self, txt: str):
        self.s: C = None
        self.x: D = None
        self.z: C = None
        self.txt = txt

c = A("c")
k = B("k")
a = C("a")
i = D("i")
g = E("g")

c.r = k
k.p = g
a.p = g
a.y = c
i.p = k
i.z = k
g.s = a
g.z = a
g.x = i
assert k.p.z.p.txt == "g"