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

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

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

h = A("h")
i = B("i")
e = C("e")
a = C("a")
c = B("c")

h.x = e
h.w = a
i.p = a
i.s = h
e.w = a
a.w = e
c.p = a
c.s = h
assert c.p.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.w: C = None
        self.txt = txt

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

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

h = A("h")
i = B("i")
e = C("e")
a = C("a")
c = B("c")

h.x = e
h.w = a
i.p = a
i.s = h
e.w = a
a.w = e
c.p = a
c.s = h
assert c.p.w.w.w.txt == "e"