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

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

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

m = A("m")
a = B("a")
d = C("d")
g = A("g")
n = B("n")
h = B("h")
e = C("e")

m.w = a
m.r = n
m.y = n
a.q = m
d.x = m
d.s = m
d.z = e
g.w = h
g.r = h
g.y = a
n.q = m
h.q = g
e.x = m
e.s = m
e.z = d
assert n.q.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.r: B = None
        self.y: B = None
        self.txt = txt

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

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

m = A("m")
a = B("a")
d = C("d")
g = A("g")
n = B("n")
h = B("h")
e = C("e")

m.w = a
m.r = n
m.y = n
a.q = m
d.x = m
d.s = m
d.z = e
g.w = h
g.r = h
g.y = a
n.q = m
h.q = g
e.x = m
e.s = m
e.z = d
assert n.q.w.q.txt == "m"