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

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

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

i = A("i")
m = B("m")
g = C("g")
f = C("f")
h = C("h")
n = A("n")

i.p = f
i.r = n
i.s = n
m.s = n
g.p = f
g.q = m
g.y = n
f.p = h
f.q = m
f.y = n
h.p = f
h.q = m
h.y = i
n.p = h
n.r = i
n.s = i
assert m.s.p.y.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.r: A = None
        self.s: A = None
        self.txt = txt

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

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

i = A("i")
m = B("m")
g = C("g")
f = C("f")
h = C("h")
n = A("n")

i.p = f
i.r = n
i.s = n
m.s = n
g.p = f
g.q = m
g.y = n
f.p = h
f.q = m
f.y = n
h.p = f
h.q = m
h.y = i
n.p = h
n.r = i
n.s = i
assert m.s.p.y.p.q.txt == "m"