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

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

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

k = A("k")
h = B("h")
j = C("j")
d = C("d")
b = C("b")
c = C("c")
g = A("g")
a = B("a")
e = B("e")
i = B("i")

k.q = h
h.y = e
h.q = k
j.w = i
d.w = e
b.w = h
c.w = e
g.q = h
a.y = e
a.q = k
e.y = i
e.q = k
i.y = a
i.q = g
assert i.q.q.q.q.y.q.q.y.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

k = A("k")
h = B("h")
j = C("j")
d = C("d")
b = C("b")
c = C("c")
g = A("g")
a = B("a")
e = B("e")
i = B("i")

k.q = h
h.y = e
h.q = k
j.w = i
d.w = e
b.w = h
c.w = e
g.q = h
a.y = e
a.q = k
e.y = i
e.q = k
i.y = a
i.q = g
assert i.q.q.q.q.y.q.q.y.y.q.txt == "g"