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

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

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

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

n.w = i
c.p = n
c.q = h
h.t = n
h.x = c
h.p = c
i.w = n
assert c.q.t.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: A = None
        self.q: C = None
        self.txt = txt

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

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

n.w = i
c.p = n
c.q = h
h.t = n
h.x = c
h.p = c
i.w = n
assert c.q.t.w.w.txt == "n"