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

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

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

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

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

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

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

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

j.q = e
j.x = e
j.s = e
a.q = g
a.w = g
i.x = m
i.z = m
e.q = j
e.x = j
e.s = j
m.x = i
m.z = i
g.q = a
g.w = a
assert g.q.q.q.w.w.txt == "a"