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

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

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

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

h.w = e
i.p = c
i.t = k
c.w = h
c.y = d
c.q = e
k.w = h
k.y = d
k.q = e
d.w = h
e.w = h
assert e.w.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

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

h.w = e
i.p = c
i.t = k
c.w = h
c.y = d
c.q = e
k.w = h
k.y = d
k.q = e
d.w = h
e.w = h
assert e.w.w.w.w.w.w.txt == "e"