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

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

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

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

d.w = f
n.s = g
n.y = f
f.q = i
e.s = i
e.y = f
g.w = f
a.s = g
a.y = f
m.s = d
m.y = f
i.w = f
assert g.w.q.w.q.w.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

d.w = f
n.s = g
n.y = f
f.q = i
e.s = i
e.y = f
g.w = f
a.s = g
a.y = f
m.s = d
m.y = f
i.w = f
assert g.w.q.w.q.w.q.w.txt == "f"