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

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

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

n = A("n")
c = B("c")
h = C("h")
i = C("i")
d = B("d")
k = A("k")

n.p = h
c.r = k
h.q = k
i.q = n
d.r = k
k.p = i
assert n.p.q.p.q.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

n = A("n")
c = B("c")
h = C("h")
i = C("i")
d = B("d")
k = A("k")

n.p = h
c.r = k
h.q = k
i.q = n
d.r = k
k.p = i
assert n.p.q.p.q.p.q.txt == "k"