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.w: C = None
        self.s: A = None
        self.txt = txt

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

n = A("n")
j = B("j")
a = C("a")
g = A("g")

n.w = g
j.p = a
j.w = a
j.s = n
a.t = n
a.z = n
g.w = n
assert n.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.w: C = None
        self.s: A = None
        self.txt = txt

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

n = A("n")
j = B("j")
a = C("a")
g = A("g")

n.w = g
j.p = a
j.w = a
j.s = n
a.t = n
a.z = n
g.w = n
assert n.w.w.w.w.txt == "n"