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

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

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

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

h.p = c
k.z = c
k.v = l
k.q = a
a.q = k
a.s = k
a.z = l
c.p = h
l.q = k
l.s = k
l.z = a
assert h.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

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

h.p = c
k.z = c
k.v = l
k.q = a
a.q = k
a.s = k
a.z = l
c.p = h
l.q = k
l.s = k
l.z = a
assert h.p.p.p.p.p.txt == "c"