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

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

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

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

h.s = c
h.y = c
h.q = n
m.r = h
m.x = h
n.s = c
c.s = h
c.y = h
c.q = n
e.s = c
i.r = h
i.x = c
l.r = c
l.x = c
d.r = c
d.x = c
assert m.r.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.q: C = None
        self.y: A = None
        self.txt = txt

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

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

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

h.s = c
h.y = c
h.q = n
m.r = h
m.x = h
n.s = c
c.s = h
c.y = h
c.q = n
e.s = c
i.r = h
i.x = c
l.r = c
l.x = c
d.r = c
d.x = c
assert m.r.s.s.txt == "h"