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

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

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

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

i.p = n
i.s = n
i.w = d
c.w = i
k.y = c
d.y = c
n.p = i
n.s = i
n.w = d
assert k.y.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.s: A = None
        self.w: C = None
        self.txt = txt

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

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

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

i.p = n
i.s = n
i.w = d
c.w = i
k.y = c
d.y = c
n.p = i
n.s = i
n.w = d
assert k.y.w.s.w.txt == "d"