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

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

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

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

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

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

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

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

c.p = h
c.z = h
h.r = k
a.w = k
a.r = k
a.u = c
g.p = k
g.z = k
k.r = h
assert h.r.r.r.r.txt == "h"