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

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

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

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

m.q = g
i.w = j
i.u = m
g.y = l
d.q = g
n.q = g
l.w = j
l.u = d
j.w = i
j.u = n
c.y = i
k.q = g
assert l.u.q.y.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

m.q = g
i.w = j
i.u = m
g.y = l
d.q = g
n.q = g
l.w = j
l.u = d
j.w = i
j.u = n
c.y = i
k.q = g
assert l.u.q.y.u.q.txt == "g"