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

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

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

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

a.p = c
g.w = c
c.t = a
c.w = g
c.z = g
f.p = k
k.t = a
k.w = g
k.z = g
assert k.z.w.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

a.p = c
g.w = c
c.t = a
c.w = g
c.z = g
f.p = k
k.t = a
k.w = g
k.z = g
assert k.z.w.t.p.txt == "c"