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

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

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

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

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

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

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

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

g.q = m
j.x = l
j.w = f
m.q = d
c.q = d
b.x = g
b.w = d
i.q = d
f.x = l
f.w = n
l.q = i
n.x = g
n.w = j
d.x = l
d.w = f
assert l.q.q.x.q.q.x.q.q.x.q.txt == "i"