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

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

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

h = A("h")
d = B("d")
m = C("m")
j = A("j")
l = A("l")
a = B("a")
i = C("i")

h.y = i
d.t = j
d.y = a
m.q = d
m.t = a
j.y = m
l.y = i
a.t = j
a.y = d
i.q = d
i.t = a
assert m.q.t.y.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

h = A("h")
d = B("d")
m = C("m")
j = A("j")
l = A("l")
a = B("a")
i = C("i")

h.y = i
d.t = j
d.y = a
m.q = d
m.t = a
j.y = m
l.y = i
a.t = j
a.y = d
i.q = d
i.t = a
assert m.q.t.y.q.y.txt == "a"