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

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

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

m = A("m")
l = B("l")
d = C("d")
h = A("h")
i = B("i")

m.p = h
m.w = l
l.p = m
d.s = m
d.v = i
h.p = m
h.w = l
i.p = h
assert d.v.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.w: B = None
        self.txt = txt

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

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

m = A("m")
l = B("l")
d = C("d")
h = A("h")
i = B("i")

m.p = h
m.w = l
l.p = m
d.s = m
d.v = i
h.p = m
h.w = l
i.p = h
assert d.v.p.p.p.p.txt == "m"