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

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

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

m = A("m")
e = B("e")
j = C("j")
g = C("g")
a = B("a")
i = B("i")

m.y = i
e.q = m
e.p = m
e.s = g
j.w = m
j.r = m
g.w = m
g.r = m
a.q = m
a.p = m
a.s = j
i.q = m
i.p = m
i.s = g
assert m.y.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

m = A("m")
e = B("e")
j = C("j")
g = C("g")
a = B("a")
i = B("i")

m.y = i
e.q = m
e.p = m
e.s = g
j.w = m
j.r = m
g.w = m
g.r = m
a.q = m
a.p = m
a.s = j
i.q = m
i.p = m
i.s = g
assert m.y.s.w.txt == "m"