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

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

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

h = A("h")
g = B("g")
n = C("n")
c = C("c")
d = B("d")
j = B("j")
a = B("a")
m = A("m")
b = A("b")
i = C("i")

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

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

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

h = A("h")
g = B("g")
n = C("n")
c = C("c")
d = B("d")
j = B("j")
a = B("a")
m = A("m")
b = A("b")
i = C("i")

h.y = b
g.x = a
g.q = c
n.w = g
c.w = j
d.x = g
d.q = n
j.x = g
j.q = n
a.x = j
a.q = i
m.y = b
b.y = h
i.w = g
assert h.y.y.y.y.y.txt == "b"