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

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

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

g = A("g")
d = B("d")
i = C("i")
k = A("k")
m = B("m")
c = C("c")

g.s = c
d.z = c
d.q = c
d.w = m
i.t = k
i.r = d
k.s = i
m.z = c
m.q = c
m.w = d
c.t = k
c.r = d
assert m.w.q.r.w.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

g = A("g")
d = B("d")
i = C("i")
k = A("k")
m = B("m")
c = C("c")

g.s = c
d.z = c
d.q = c
d.w = m
i.t = k
i.r = d
k.s = i
m.z = c
m.q = c
m.w = d
c.t = k
c.r = d
assert m.w.q.r.w.w.q.txt == "c"